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 cannot read property 'annotations' of null #7857

Merged
merged 3 commits into from
May 8, 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/20240507_103107_boris_fixed_exception.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Cannot read property 'annotations' of null when uploading annotations into a job
(<https://github.com/cvat-ai/cvat/pull/7857>)
2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.63.9",
"version": "1.63.10",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
9 changes: 8 additions & 1 deletion cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,12 +869,19 @@ export function resetCanvas(): AnyAction {
}

export function closeJob(): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
return async (dispatch: ActionCreator<Dispatch>, getState): Promise<void> => {
const state = getState();
const { instance: canvasInstance } = state.annotation.canvas;
const { jobInstance } = receiveAnnotationsParameters();

if (jobInstance) {
await jobInstance.close();
}

if (canvasInstance) {
canvasInstance.destroy();
}

dispatch({
type: AnnotationActionTypes.CLOSE_JOB,
});
Expand Down
26 changes: 12 additions & 14 deletions cvat-ui/src/actions/import-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import { createAction, ActionUnion, ThunkAction } from 'utils/redux';
import { CombinedState } from 'reducers';
import { getCore, Storage } from 'cvat-core-wrapper';
import {
getCore, Storage, Job, Task, Project,
} from 'cvat-core-wrapper';
import { EventScope } from 'cvat-logger';
import { getProjectsAsync } from './projects-actions';
import { AnnotationActionTypes, fetchAnnotationsAsync } from './annotation-actions';
Expand Down Expand Up @@ -36,10 +38,10 @@ export const importActions = {
importDataset: (instance: any, format: string) => (
createAction(ImportActionTypes.IMPORT_DATASET, { instance, format })
),
importDatasetSuccess: (instance: any, resource: 'dataset' | 'annotation') => (
importDatasetSuccess: (instance: Job | Task | Project, resource: 'dataset' | 'annotation') => (
createAction(ImportActionTypes.IMPORT_DATASET_SUCCESS, { instance, resource })
),
importDatasetFailed: (instance: any, resource: 'dataset' | 'annotation', error: any) => (
importDatasetFailed: (instance: Job | Task | Project, resource: 'dataset' | 'annotation', error: any) => (
createAction(ImportActionTypes.IMPORT_DATASET_FAILED, {
instance,
resource,
Expand Down Expand Up @@ -112,22 +114,18 @@ export const importDatasetAsync = (
await instance.logger.log(EventScope.uploadAnnotations);
await instance.annotations.clear(true);
await instance.actions.clear();
const history = await instance.actions.get();

// first set empty objects list
// to escape some problems in canvas when shape with the same
// clientID has different type (polygon, rectangle) for example
dispatch({
type: AnnotationActionTypes.UPLOAD_JOB_ANNOTATIONS_SUCCESS,
payload: {
states: [],
history,
},
});
dispatch({ type: AnnotationActionTypes.UPLOAD_JOB_ANNOTATIONS_SUCCESS });

setTimeout(() => {
dispatch(fetchAnnotationsAsync());
});
const relevantInstance = getState().annotation.job.instance;
if (relevantInstance && relevantInstance.id === instance.id) {
setTimeout(() => {
dispatch(fetchAnnotationsAsync());
});
}
}
} catch (error) {
dispatch(importActions.importDatasetFailed(instance, resource, error));
Expand Down
8 changes: 2 additions & 6 deletions cvat-ui/src/components/annotation-page/annotation-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-License-Identifier: MIT

import React, { useEffect } from 'react';
import { useHistory } from 'react-router';
import Layout from 'antd/lib/layout';
import Result from 'antd/lib/result';
import Spin from 'antd/lib/spin';
Expand Down Expand Up @@ -44,7 +43,6 @@ export default function AnnotationPageComponent(props: Props): JSX.Element {
const prevJob = usePrevious(job);
const prevFetching = usePrevious(fetching);

const history = useHistory();
useEffect(() => {
saveLogs();
const root = window.document.getElementById('root');
Expand All @@ -54,13 +52,11 @@ export default function AnnotationPageComponent(props: Props): JSX.Element {

return () => {
saveLogs();
closeJob();

if (root) {
root.style.minHeight = '';
}

if (!history.location.pathname.includes('/jobs')) {
closeJob();
}
};
}, []);

Expand Down
14 changes: 6 additions & 8 deletions cvat-ui/src/reducers/annotation-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,16 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
};
}
case AnnotationActionTypes.UPLOAD_JOB_ANNOTATIONS_SUCCESS: {
const { states, history } = action.payload;

return {
...state,
annotations: {
...state.annotations,
history,
states,
history: { undo: [], redo: [] },
states: [],
activatedStateID: null,
activatedElementID: null,
activatedAttributeID: null,
highlightedConflict: null,
collapsed: {},
},
};
Expand Down Expand Up @@ -1083,10 +1084,7 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
}
case AnnotationActionTypes.CLOSE_JOB:
case AuthActionTypes.LOGOUT_SUCCESS: {
if (state.canvas.instance) {
state.canvas.instance.destroy();
}
return { ...defaultState };
return defaultState;
}
default: {
return state;
Expand Down
17 changes: 12 additions & 5 deletions cvat-ui/src/reducers/notifications-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { AnyAction } from 'redux';

import { ServerError } from 'cvat-core-wrapper';
import { Project, ServerError, Task } from 'cvat-core-wrapper';
import { AuthActionTypes } from 'actions/auth-actions';
import { FormatsActionTypes } from 'actions/formats-actions';
import { ModelsActionTypes } from 'actions/models-actions';
Expand Down Expand Up @@ -567,10 +567,17 @@ export default function (state = defaultState, action: AnyAction): Notifications
}
case ImportActionTypes.IMPORT_DATASET_SUCCESS: {
const { instance, resource } = action.payload;
const message = resource === 'annotation' ?
'Annotations have been loaded to the ' +
`[task ${instance.taskId || instance.id}](/tasks/${instance.taskId || instance.id}) ` :
`Dataset was imported to the [project ${instance.id}](/projects/${instance.id})`;
let message = resource === 'annotation' ?
'Annotations have been loaded to the ' :
'Dataset was imported to the ';
if (instance instanceof Project) {
message += `[Project ${instance.id}](/projects/${instance.id})`;
} else if (instance instanceof Task) {
message += `[Task ${instance.id}](/tasks/${instance.id})`;
} else {
message += `[Job ${instance.id}](/jobs/${instance.id})`;
}

return {
...state,
messages: {
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/src/reducers/review-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default function (state: ReviewState = defaultState, action: any): Review
}
case AnnotationActionTypes.CLOSE_JOB:
case AuthActionTypes.LOGOUT_SUCCESS: {
return { ...defaultState };
return defaultState;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we apply such approach for all the default state actions? We have plenty of return { ...defaultState } in other places

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at the fact that defaultState is usually a deeply nested object, destructurization on top level looks useless.

So, in the future, yes.

}
default:
return state;
Expand Down
8 changes: 1 addition & 7 deletions cvat-ui/src/reducers/tasks-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022-2023 CVAT.ai Corporation
// Copyright (C) 2022-2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -8,7 +8,6 @@ import { BoundariesActionTypes } from 'actions/boundaries-actions';
import { TasksActionTypes } from 'actions/tasks-actions';
import { AuthActionTypes } from 'actions/auth-actions';

import { AnnotationActionTypes } from 'actions/annotation-actions';
import { TasksState } from '.';

const defaultState: TasksState = {
Expand Down Expand Up @@ -136,11 +135,6 @@ export default (state: TasksState = defaultState, action: AnyAction): TasksState
},
};
}
case AnnotationActionTypes.CLOSE_JOB: {
return {
...state,
};
}
case BoundariesActionTypes.RESET_AFTER_ERROR:
case AuthActionTypes.LOGOUT_SUCCESS: {
return { ...defaultState };
Expand Down
Loading