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

Fixed issue: Cannot read properties of undefined (reading 'getUpdated') #8785

Merged
merged 7 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/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
Loading