Skip to content

Commit 2bbf217

Browse files
bsekachevChris Lee-Messer
authored andcommitted
Fixed comparison of shapes (cvat-ai#1000)
1 parent 8e60699 commit 2bbf217

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

cvat-core/src/annotations-saver.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,18 @@
102102
},
103103
};
104104

105+
const keys = ['id', 'label_id', 'group', 'frame',
106+
'occluded', 'z_order', 'points', 'type', 'shapes',
107+
'attributes', 'value', 'spec_id', 'outside'];
108+
105109
// Find created and updated objects
106110
for (const type of Object.keys(exported)) {
107111
for (const object of exported[type]) {
108112
if (object.id in this.initialObjects[type]) {
109-
const exportedHash = JSON.stringify(object);
110-
const initialHash = JSON.stringify(this.initialObjects[type][object.id]);
113+
const exportedHash = JSON.stringify(object, keys);
114+
const initialHash = JSON.stringify(
115+
this.initialObjects[type][object.id], keys,
116+
);
111117
if (exportedHash !== initialHash) {
112118
splitted.updated[type].push(object);
113119
}

cvat/apps/engine/static/engine/js/annotationSaver.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,18 @@ class AnnotationSaverModel extends Listener {
151151
tags: [],
152152
};
153153

154+
const keys = ['id', 'label_id', 'group', 'frame',
155+
'occluded', 'z_order', 'points', 'type', 'shapes',
156+
'attributes', 'value', 'spec_id', 'outside'];
157+
154158
// Compare initial state objects and export state objects
155159
// in order to get updated and created objects
156160
for (const type of Object.keys(this._initialObjects)) {
157161
for (const obj of exported[type]) {
158162
if (obj.id in this._initialObjects[type]) {
159-
const exportedHash = JSON.stringify(obj);
160-
const initialSash = JSON.stringify(this._initialObjects[type][obj.id]);
161-
if (exportedHash !== initialSash) {
163+
const exportedHash = JSON.stringify(obj, keys);
164+
const initialHash = JSON.stringify(this._initialObjects[type][obj.id], keys);
165+
if (exportedHash !== initialHash) {
162166
updated[type].push(obj);
163167
}
164168
} else if (typeof obj.id === 'undefined') {
@@ -241,20 +245,33 @@ class AnnotationSaverModel extends Listener {
241245
this._shapeCollection.flush = false;
242246
this._version = savedObjects.version;
243247
this._resetState();
248+
244249
for (const type of Object.keys(this._initialObjects)) {
245250
for (const object of savedObjects[type]) {
251+
if (object.shapes) {
252+
for (const shape of object.shapes) {
253+
delete shape.id;
254+
}
255+
}
246256
this._initialObjects[type][object.id] = object;
247257
}
248258
}
259+
249260
this._version = savedObjects.version;
250261
} else {
251262
const [created, updated, deleted] = this._split(exported);
252263
this.notify('saveCreated');
253264
const savedCreated = await this._create(created);
254265
this._updateCreatedObjects(created, savedCreated, mapping);
255266
this._version = savedCreated.version;
267+
256268
for (const type of Object.keys(this._initialObjects)) {
257269
for (const object of savedCreated[type]) {
270+
if (object.shapes) {
271+
for (const shape of object.shapes) {
272+
delete shape.id;
273+
}
274+
}
258275
this._initialObjects[type][object.id] = object;
259276
}
260277
}
@@ -264,6 +281,11 @@ class AnnotationSaverModel extends Listener {
264281
this._version = savedUpdated.version;
265282
for (const type of Object.keys(this._initialObjects)) {
266283
for (const object of savedUpdated[type]) {
284+
if (object.shapes) {
285+
for (const shape of object.shapes) {
286+
delete shape.id;
287+
}
288+
}
267289
this._initialObjects[type][object.id] = object;
268290
}
269291
}
@@ -375,7 +397,7 @@ class AnnotationSaverView {
375397
});
376398

377399
window.onbeforeunload = (e) => {
378-
if (this._controller.hasUnsavedChanges()) { // eslint-disable-line react/no-this-in-sfc
400+
if (this._controller.hasUnsavedChanges()) {
379401
const message = 'You have unsaved changes. Leave this page?';
380402
e.returnValue = message;
381403
return message;

0 commit comments

Comments
 (0)