Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set properties of undefined (setting 'serverID') #7882

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.d/20240513_125509_boris_fixed_tracks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

Exception **"Cannot set properties of undefined (setting 'serverID')"** occurs when attempting to save a job after removing the first keyframe of a track (<https://github.com/cvat-ai/cvat/pull/7882>)
after removing the first keyframe of a track (<https://github.com/cvat-ai/cvat/pull/7882>)
bsekachev marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 42 additions & 1 deletion cvat-core/src/annotations-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,16 @@ export class Track extends Drawn {
);
}

protected appendShapeActionToHistory(actionType, frame, undoShape, redoShape, undoSource, redoSource): void {
protected appendShapeActionToHistory(
actionType,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
): void {
Comment on lines +1142 to +1151
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to improve readability of appendShapeActionToHistory.

- this.history.do(
-     actionType,
-     () => {
-         if (!undoShape) {
-             delete this.shapes[frame];
-         } else {
-             this.shapes[frame] = undoShape;
-         }
-         this.source = undoSource;
-         this.frame = undoFrame;
-         this.updated = Date.now();
-     },
-     () => {
-         if (!redoShape) {
-             delete this.shapes[frame];
-         } else {
-             this.shapes[frame] = redoShape;
-         }
-         this.source = redoSource;
-         this.frame = redoFrame;
-         this.updated = Date.now();
-     },
-     [this.clientID],
-     frame,
- );
+ this.history.do(
+     actionType,
+     this.createHistoryCallback(undoShape, undoSource, undoFrame),
+     this.createHistoryCallback(redoShape, redoSource, redoFrame),
+     [this.clientID],
+     frame,
+ );
+
+ // Helper method to create a history callback
+ protected createHistoryCallback(shape, source, frame) {
+     return () => {
+         if (!shape) {
+             delete this.shapes[frame];
+         } else {
+             this.shapes[frame] = shape;
+         }
+         this.source = source;
+         this.frame = frame;
+         this.updated = Date.now();
+     };
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
protected appendShapeActionToHistory(
actionType,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
): void {
protected appendShapeActionToHistory(
actionType,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
): void {
this.history.do(
actionType,
this.createHistoryCallback(undoShape, undoSource, undoFrame),
this.createHistoryCallback(redoShape, redoSource, redoFrame),
[this.clientID],
frame,
);
}
// Helper method to create a history callback
protected createHistoryCallback(shape, source, frame) {
return () => {
if (!shape) {
delete this.shapes[frame];
} else {
this.shapes[frame] = shape;
}
this.source = source;
this.frame = frame;
this.updated = Date.now();
};
}

this.history.do(
actionType,
() => {
Expand All @@ -1142,6 +1151,7 @@ export class Track extends Drawn {
this.shapes[frame] = undoShape;
}
this.source = undoSource;
this.frame = undoFrame;
this.updated = Date.now();
},
() => {
Expand All @@ -1151,6 +1161,7 @@ export class Track extends Drawn {
this.shapes[frame] = redoShape;
}
this.source = redoSource;
this.frame = redoFrame;
this.updated = Date.now();
},
[this.clientID],
Expand All @@ -1162,102 +1173,127 @@ export class Track extends Drawn {
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = this.readOnlyFields.includes('source') ? this.source : computeNewSource(this.source);
const undoFrame = this.frame;
const redoFrame = Math.min(frame, this.frame);
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ?
{ ...this.shapes[frame], rotation } : copyShape(this.get(frame), { rotation });

this.shapes[frame] = redoShape;
this.source = redoSource;
this.frame = redoFrame;
this.appendShapeActionToHistory(
HistoryActions.CHANGED_ROTATION,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
);
}

protected savePoints(points: number[], frame: number): void {
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = this.readOnlyFields.includes('source') ? this.source : computeNewSource(this.source);
const undoFrame = this.frame;
const redoFrame = Math.min(frame, this.frame);
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ?
{ ...this.shapes[frame], points } : copyShape(this.get(frame), { points });

this.shapes[frame] = redoShape;
this.source = redoSource;
this.frame = redoFrame;
this.appendShapeActionToHistory(
HistoryActions.CHANGED_POINTS,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
);
}

protected saveOutside(frame: number, outside: boolean): void {
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = this.readOnlyFields.includes('source') ? this.source : computeNewSource(this.source);
const undoFrame = this.frame;
const redoFrame = Math.min(frame, this.frame);
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ?
{ ...this.shapes[frame], outside } :
copyShape(this.get(frame), { outside });

this.shapes[frame] = redoShape;
this.source = redoSource;
this.frame = redoFrame;
this.appendShapeActionToHistory(
HistoryActions.CHANGED_OUTSIDE,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
);
}

protected saveOccluded(occluded: boolean, frame: number): void {
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = this.readOnlyFields.includes('source') ? this.source : computeNewSource(this.source);
const undoFrame = this.frame;
const redoFrame = Math.min(frame, this.frame);
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ?
{ ...this.shapes[frame], occluded } :
copyShape(this.get(frame), { occluded });

this.shapes[frame] = redoShape;
this.source = redoSource;
this.frame = redoFrame;
this.appendShapeActionToHistory(
HistoryActions.CHANGED_OCCLUDED,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
);
}

protected saveZOrder(zOrder: number, frame: number): void {
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = this.readOnlyFields.includes('source') ? this.source : computeNewSource(this.source);
const undoFrame = this.frame;
const redoFrame = Math.min(frame, this.frame);
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ?
{ ...this.shapes[frame], zOrder } :
copyShape(this.get(frame), { zOrder });

this.shapes[frame] = redoShape;
this.source = redoSource;
this.frame = redoFrame;
this.appendShapeActionToHistory(
HistoryActions.CHANGED_ZORDER,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
);
}

Expand All @@ -1270,6 +1306,7 @@ export class Track extends Drawn {

const undoSource = this.source;
const redoSource = this.readOnlyFields.includes('source') ? this.source : computeNewSource(this.source);
const undoFrame = this.frame;
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = keyframe ? copyShape(this.get(frame)) : undefined;

Expand All @@ -1279,6 +1316,8 @@ export class Track extends Drawn {
} else {
delete this.shapes[frame];
}
const redoFrame = Math.min(...Object.keys(this.shapes).map((key) => +key));
this.frame = redoFrame;

this.appendShapeActionToHistory(
HistoryActions.CHANGED_KEYFRAME,
Expand All @@ -1287,6 +1326,8 @@ export class Track extends Drawn {
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
);
}

Expand Down
Loading