Skip to content

Commit

Permalink
Fixed issue: Cannot read properties of undefined (reading 'getUpdated…
Browse files Browse the repository at this point in the history
…') (cvat-ai#8785)
  • Loading branch information
bsekachev authored Dec 6, 2024
1 parent caff6ee commit 12eec54
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20241206_153723_sekachev.bs_fixed_issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Fixed issue: Cannot read properties of undefined (reading 'getUpdated')
(<https://github.com/cvat-ai/cvat/pull/8785>)
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "15.3.0",
"version": "15.3.1",
"type": "module",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
Expand Down
64 changes: 39 additions & 25 deletions cvat-core/src/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,41 +536,55 @@ Object.defineProperty(FrameData.prototype.data, 'implementation', {
writable: false,
});

export async function getFramesMeta(type: 'job' | 'task', id: number, forceReload = false): Promise<FramesMetaData> {
export function getFramesMeta(type: 'job' | 'task', id: number, forceReload = false): Promise<FramesMetaData> {
if (type === 'task') {
// we do not cache task meta currently. So, each new call will results to the server request
const result = await serverProxy.frames.getMeta('task', id);
return new FramesMetaData({
...result,
deleted_frames: Object.fromEntries(result.deleted_frames.map((_frame) => [_frame, true])),
});
return serverProxy.frames.getMeta('task', id).then((serialized) => (
new FramesMetaData({
...serialized,
deleted_frames: Object.fromEntries(serialized.deleted_frames.map((_frame) => [_frame, true])),
})
));
}

if (!(id in frameMetaCache) || forceReload) {
frameMetaCache[id] = serverProxy.frames.getMeta('job', id)
.then((serverMeta) => new FramesMetaData({
...serverMeta,
deleted_frames: Object.fromEntries(serverMeta.deleted_frames.map((_frame) => [_frame, true])),
}))
.catch((error) => {
const previousCache = frameMetaCache[id];
frameMetaCache[id] = new Promise((resolve, reject) => {
serverProxy.frames.getMeta('job', id).then((serialized) => {
const framesMetaData = new FramesMetaData({
...serialized,
deleted_frames: Object.fromEntries(serialized.deleted_frames.map((_frame) => [_frame, true])),
});
resolve(framesMetaData);
}).catch((error: unknown) => {
delete frameMetaCache[id];
throw error;
if (previousCache instanceof Promise) {
frameMetaCache[id] = previousCache;
}
reject(error);
});
});
}

return frameMetaCache[id];
}

async function saveJobMeta(meta: FramesMetaData, jobID: number): Promise<FramesMetaData> {
frameMetaCache[jobID] = serverProxy.frames.saveMeta('job', jobID, {
deleted_frames: Object.keys(meta.deletedFrames).map((frame) => +frame),
})
.then((serverMeta) => new FramesMetaData({
...serverMeta,
deleted_frames: Object.fromEntries(serverMeta.deleted_frames.map((_frame) => [_frame, true])),
}))
.catch((error) => {
delete frameMetaCache[jobID];
throw error;
function saveJobMeta(meta: FramesMetaData, jobID: number): Promise<FramesMetaData> {
frameMetaCache[jobID] = new Promise<FramesMetaData>((resolve, reject) => {
serverProxy.frames.saveMeta('job', jobID, {
deleted_frames: Object.keys(meta.deletedFrames).map((frame) => +frame),
}).then((serverMeta) => {
const updatedMetaData = new FramesMetaData({
...serverMeta,
deleted_frames: Object.fromEntries(serverMeta.deleted_frames.map((_frame) => [_frame, true])),
});
resolve(updatedMetaData);
}).catch((error) => {
frameMetaCache[jobID] = Promise.resolve(meta);
reject(error);
});
});

return frameMetaCache[jobID];
}

Expand Down Expand Up @@ -834,7 +848,7 @@ export async function patchMeta(jobID: number): Promise<FramesMetaData> {
const updatedFields = meta.getUpdated();

if (Object.keys(updatedFields).length) {
frameMetaCache[jobID] = saveJobMeta(meta, jobID);
await saveJobMeta(meta, jobID);
}
const newMeta = await frameMetaCache[jobID];
return newMeta;
Expand Down

0 comments on commit 12eec54

Please sign in to comment.