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

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented May 13, 2024

Motivation and context

Resolved #7879

Motivation:

  • Track.frame should be always equal to the frame with the first shape of the track
  • Lock for a skeleton works incorrectly (if all child locked, parent must not be locked. Instead, if parent is locked, all children must be locked).

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • Refactor
    • Improved history management for frame and shape actions to enhance consistency.
    • Simplified getter functions for object properties to streamline logic and control flow.

Copy link
Contributor

coderabbitai bot commented May 13, 2024

Warning

Rate Limit Exceeded

@bsekachev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 50 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 48494ae and dd33779.

Walkthrough

The changes in cvat-core focus on enhancing the Track and SkeletonTrack classes to improve history management by tracking frame changes alongside shape actions. Additionally, getter functions in the ObjectState class are simplified to streamline the logic.

Changes

File Change Summary
cvat-core/src/annotations-objects.ts Refactored appendShapeActionToHistory to include undoFrame and redoFrame. Adjusted methods in Track and SkeletonTrack for frame updates and shape modifications.
cvat-core/src/object-state.ts Simplified getter functions by removing conditional checks related to ShapeType.SKELETON.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant Track
    participant SkeletonTrack

    User->>Track: Modify shape
    Track->>Track: appendShapeActionToHistory(actionType, frame, undoShape, redoShape, undoSource, redoSource, undoFrame, redoFrame)
    Track->>SkeletonTrack: Update frame and shape
    SkeletonTrack->>Track: Confirmation of update
    User->>Track: Save track
    Track->>User: Track saved successfully

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Ensure annotations can be saved after removing the first keyframe and updating the track (#7879)

In the code's realm where changes flow,
Frames and shapes in tandem grow.
With history tracked, and getters clear,
Errors fade, there's naught to fear.
Rabbit's touch, a code delight,
Ensures the future's bright. 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@bsekachev bsekachev requested a review from nmanovic as a code owner May 13, 2024 09:56
@bsekachev bsekachev requested review from klakhov and removed request for nmanovic May 13, 2024 09:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 899735d and 489cdd6.
Files selected for processing (1)
  • cvat-core/src/annotations-objects.ts (7 hunks)
Additional comments not posted (1)
cvat-core/src/annotations-objects.ts (1)

Line range hint 1135-1164: The addition of undoFrame and redoFrame parameters to appendShapeActionToHistory enhances the method's functionality by allowing frame-specific undo and redo actions. This is a positive change for maintaining a detailed history of shape modifications across different frames.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 489cdd6 and cb4d19b.
Files selected for processing (1)
  • changelog.d/20240513_125509_boris_fixed_tracks.md (1 hunks)
Additional Context Used
LanguageTool (1)
changelog.d/20240513_125509_boris_fixed_tracks.md (1)

Near line 3: Before the countable noun ‘save’ an article or a possessive pronoun is necessary.
Context: ...ting 'serverID')"** when trying to save job after removing the first keyframe of a ...

changelog.d/20240513_125509_boris_fixed_tracks.md Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@bsekachev bsekachev changed the title Cannot set properties of undefined (setting 'serverID') [WIP] Cannot set properties of undefined (setting 'serverID') May 16, 2024
@bsekachev bsekachev changed the title [WIP] Cannot set properties of undefined (setting 'serverID') Cannot set properties of undefined (setting 'serverID') May 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (9)
cvat-core/src/object-state.ts (4)

Line range hint 230-235: Consider using for...of instead of forEach for better readability and performance in modern JavaScript environments.

- data.elements.forEach((element: ObjectState) => {
-     element.hidden = hidden;
- });
+ for (const element of data.elements) {
+     element.hidden = hidden;
+ }

Line range hint 245-245: Optimize the mapping and flattening of points by using .flatMap() instead of .map().flat().

- return data.elements.map((element) => element.points).flat();
+ return data.elements.flatMap((element) => element.points);

Line range hint 257-260: Use template literals for string concatenation to improve readability and maintainability.

- 'Points are expected to be an array of numbers but got ' + typeof points === 'object' ? points.constructor.name : typeof points
+ `Points are expected to be an array of numbers but got ${typeof points === 'object' ? points.constructor.name : typeof points}`

- 'Tried to set wrong number of points for a skeleton' + `(${points.length} vs ${currentPoints.length}})`
+ `Tried to set wrong number of points for a skeleton (${points.length} vs ${currentPoints.length})`

- 'Attributes are expected to be an object but got ' + typeof attributes === 'object' ? attributes.constructor.name : typeof attributes
+ `Attributes are expected to be an object but got ${typeof attributes === 'object' ? attributes.constructor.name : typeof attributes}`

Also applies to: 268-269, 386-391


Line range hint 490-490: Use optional chaining to safely access properties.

- if (serialized.__internal) {
+ if (serialized.__internal?) {

- if (this.__internal && this.__internal.delete) {
+ if (this.__internal?.delete) {

Also applies to: 501-501

cvat-core/src/annotations-objects.ts (5)

Line range hint 322-323: Use template literals for string operations to improve readability and performance.

- 'No one left position or right position was found. ' + 'Interpolation impossible. Client ID: ' + this.clientID
+ `No one left position or right position was found. Interpolation impossible. Client ID: ${this.clientID}`

Line range hint 1436-1437: Use template literals for string operations to improve readability and performance.

- 'An unexpected type of shape "' + type + '"'
+ `An unexpected type of shape "${type}"`

Line range hint 70-70: Specify explicit types instead of using any to enhance type safety and code maintainability.

Consider defining a more specific type or interface that accurately represents the expected structure of the data.

Also applies to: 146-146, 333-333, 1414-1414


Line range hint 2633-2633: Remove unnecessary return statements in functions declared with a void return type.

- return;

Also applies to: 2637-2637, 2716-2716


Line range hint 2681-2690: Remove unnecessary else clause after continue statement to simplify control flow.

- else if (y2 <= y) {
-     if (position(x1, y1, x2, y2) < 0) {
-         wn--;
-     }
- }
+ else if (y2 <= y && position(x1, y1, x2, y2) < 0) {
+     wn--;
+ }
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cb4d19b and 9ef4b1b.
Files selected for processing (3)
  • changelog.d/20240513_125509_boris_fixed_tracks.md (1 hunks)
  • cvat-core/src/annotations-objects.ts (19 hunks)
  • cvat-core/src/object-state.ts (7 hunks)
Additional Context Used
Biome (27)
cvat-core/src/annotations-objects.ts (20)

70-70: Unexpected any. Specify a different type.


146-146: Unexpected any. Specify a different type.


322-323: Template literals are preferred over string concatenation.


333-333: Unexpected any. Specify a different type.


451-451: Prefer for...of instead of forEach.


1414-1414: Unexpected any. Specify a different type.


1436-1437: Template literals are preferred over string concatenation.


2172-2172: Prefer for...of instead of forEach.


2173-2173: Prefer for...of instead of forEach.


2174-2174: Prefer for...of instead of forEach.


2181-2181: Prefer for...of instead of forEach.


2186-2186: Prefer for...of instead of forEach.


2191-2191: Prefer for...of instead of forEach.


2633-2633: The function should not return a value because its return type is void.


2637-2637: The function should not return a value because its return type is void.


2681-2681: Unnecessary continue statement


2682-2690: This else clause can be omitted because previous branches break early.


2716-2716: The function should not return a value because its return type is void.


2900-2903: Prefer for...of instead of forEach.


3037-3039: Prefer for...of instead of forEach.

cvat-core/src/object-state.ts (7)

233-235: Prefer for...of instead of forEach.


245-245: The call chain .map().flat() can be replaced with a single .flatMap() call.


257-260: Template literals are preferred over string concatenation.


268-269: Template literals are preferred over string concatenation.


386-391: Template literals are preferred over string concatenation.


490-490: Change to an optional chain.


501-501: Change to an optional chain.

Additional comments not posted (2)
changelog.d/20240513_125509_boris_fixed_tracks.md (1)

3-4: The changelog entry is clear and effectively communicates the fix related to the 'serverID' issue.

cvat-core/src/annotations-objects.ts (1)

1135-1144: Refactor appendShapeActionToHistory to include new parameters for better history management.

This change allows tracking frame changes alongside shape actions, which enhances the undo/redo functionality by providing more context about the state changes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range and nitpick comments (4)
cvat-core/src/object-state.ts (4)

Line range hint 230-235: Prefer using for...of instead of forEach for better readability and performance.

- data.elements.forEach((element: ObjectState) => {
-     element.hidden = hidden;
- });
+ for (const element of data.elements) {
+     element.hidden = hidden;
+ }

Line range hint 245-245: Use .flatMap() instead of .map().flat() for more efficient array flattening.

- return data.elements.map((element) => element.points).flat();
+ return data.elements.flatMap((element) => element.points);

Line range hint 257-260: Use template literals for string concatenation to improve readability and maintainability.

- 'Points are expected to be an array of numbers ' +
-     `but got ${
-         typeof points === 'object' ? points.constructor.name : typeof points
-     }`,
+ `Points are expected to be an array of numbers but got ${typeof points === 'object' ? points.constructor.name : typeof points}`,

- 'Tried to set wrong number of points for a skeleton' +
-     `(${points.length} vs ${currentPoints.length}})`,
+ `Tried to set wrong number of points for a skeleton (${points.length} vs ${currentPoints.length})`,

- 'Attributes are expected to be an object ' +
-     `but got ${
-         typeof attributes === 'object' ?
-             attributes.constructor.name :
-             typeof attributes
-     }`,
+ `Attributes are expected to be an object but got ${typeof attributes === 'object' ? attributes.constructor.name : typeof attributes}`,

Also applies to: 268-269, 385-390


Line range hint 489-489: Consider using optional chaining to safely access properties.

- if (serialized.__internal) {
+ if (serialized.__internal?) {

- if (this.__internal && this.__internal.delete) {
+ if (this.__internal?.delete) {

Also applies to: 500-500

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9ef4b1b and 48494ae.
Files selected for processing (2)
  • cvat-core/src/annotations-objects.ts (31 hunks)
  • cvat-core/src/object-state.ts (6 hunks)
Additional Context Used
Biome (27)
cvat-core/src/annotations-objects.ts (20)

85-85: Unexpected any. Specify a different type.


161-161: Unexpected any. Specify a different type.


337-338: Template literals are preferred over string concatenation.


466-466: Prefer for...of instead of forEach.


1421-1421: Unexpected any. Specify a different type.


1443-1444: Template literals are preferred over string concatenation.


2180-2180: Prefer for...of instead of forEach.


2181-2181: Prefer for...of instead of forEach.


2182-2182: Prefer for...of instead of forEach.


2189-2189: Prefer for...of instead of forEach.


2194-2194: Prefer for...of instead of forEach.


2199-2199: Prefer for...of instead of forEach.


2641-2641: The function should not return a value because its return type is void.


2645-2645: The function should not return a value because its return type is void.


2689-2689: Unnecessary continue statement


2690-2698: This else clause can be omitted because previous branches break early.


2724-2724: The function should not return a value because its return type is void.


2908-2911: Prefer for...of instead of forEach.


3045-3047: Prefer for...of instead of forEach.


3055-3065: Prefer for...of instead of forEach.

cvat-core/src/object-state.ts (7)

233-235: Prefer for...of instead of forEach.


245-245: The call chain .map().flat() can be replaced with a single .flatMap() call.


257-260: Template literals are preferred over string concatenation.


268-269: Template literals are preferred over string concatenation.


385-390: Template literals are preferred over string concatenation.


489-489: Change to an optional chain.


500-500: Change to an optional chain.

Additional comments not posted (2)
cvat-core/src/annotations-objects.ts (2)

836-836: Verify that serverTrackedShapeToClient handles all necessary fields.

Verification successful

The function serverTrackedShapeToClient has been located and its implementation analyzed. It appears to handle the necessary fields from SerializedTrack['shapes'][0] as follows:

  • id is mapped to serverID
  • occluded is directly mapped
  • z_order is mapped to zOrder
  • points is directly mapped
  • outside is directly mapped
  • rotation is mapped with a default value of 0 if not present
  • attributes are processed and accumulated into an object

Based on this analysis, it seems that serverTrackedShapeToClient handles all the necessary fields from SerializedTrack['shapes'][0].

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `serverTrackedShapeToClient` handles all necessary fields.

# Test: Search for the implementation of `serverTrackedShapeToClient`. Expect: All fields from `SerializedTrack['shapes'][0]` are handled.
ast-grep --lang typescript --pattern $'function serverTrackedShapeToClient($_) { $$$ }'

Length of output: 88



Script:

#!/bin/bash
# Description: Locate the implementation of `serverTrackedShapeToClient` and verify it handles all necessary fields.

# Step 1: Locate the implementation of `serverTrackedShapeToClient`.
rg 'function serverTrackedShapeToClient' -t typescript

# Step 2: Once located, extract the function implementation to analyze its handling of fields.
# Note: The following command will be executed only if the function is found in the previous step.
rg -A 20 'function serverTrackedShapeToClient' -t typescript

Length of output: 189



Script:

#!/bin/bash
# Description: Locate the implementation of `serverTrackedShapeToClient` and verify it handles all necessary fields.

# Step 1: Find all TypeScript files.
fd -e ts

# Step 2: Search for the implementation of `serverTrackedShapeToClient` within the found TypeScript files.
fd -e ts -x rg 'function serverTrackedShapeToClient' {}

# Step 3: Once located, extract the function implementation to analyze its handling of fields.
# Note: The following command will be executed only if the function is found in the previous step.
fd -e ts -x rg -A 20 'function serverTrackedShapeToClient' {}

Length of output: 7578


348-348: Ensure proper error handling when updating server IDs.

Comment on lines +1142 to +1151
protected appendShapeActionToHistory(
actionType,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
undoFrame,
redoFrame,
): void {
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();
};
}

Comment on lines +3045 to +3047
result.shapes.forEach((shape) => {
shape.points = [];
});
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 use for...of loop for better performance and readability.

- result.shapes.forEach((shape) => {
-     shape.points = [];
- });
+ for (const shape of result.shapes) {
+     shape.points = [];
+ }

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
result.shapes.forEach((shape) => {
shape.points = [];
});
for (const shape of result.shapes) {
shape.points = [];
}

Comment on lines +2908 to +2911
Object.values(this.shapes).forEach((shape) => {
// skeletons do not have their own points
shape.points = [];
});
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 use for...of loop for better performance and readability.

- Object.values(this.shapes).forEach((shape) => {
-     shape.points = [];
- });
+ for (const shape of Object.values(this.shapes)) {
+     shape.points = [];
+ }

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
Object.values(this.shapes).forEach((shape) => {
// skeletons do not have their own points
shape.points = [];
});
for (const shape of Object.values(this.shapes)) {
// skeletons do not have their own points
shape.points = [];
}

@bsekachev
Copy link
Member Author

I want to find another way, but this PR still contains lots of useful ideas I will apply later.

@bsekachev bsekachev closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot set properties of undefined (setting 'serverID') cvat
1 participant