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 propagate in ground truth tasks with sparsed frames #8550

Merged
merged 15 commits into from
Nov 1, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Oct 16, 2024

Motivation and context

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

Release Notes

  • New Features

    • Enhanced shape propagation functionality to accommodate multiple frames and improve frame number handling.
    • Introduced a new method for computing segment frame numbers based on job start frames.
  • Bug Fixes

    • Resolved issues with the propagation mechanism to prevent unnecessary copies of non-existent frames.
    • Improved validation checks for frame indices in job and task classes.
  • Improvements

    • Refined state management in the annotation system to include frame numbers.
    • Enhanced error handling in frame and annotation management methods.

These updates improve the overall robustness and user experience within the annotation framework.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduced in this pull request focus on enhancing the propagation mechanism and frame handling within the annotation framework. Key updates include the introduction of new methods for frame number retrieval, modifications to existing methods for better type safety and flexibility, and improvements in state management within the UI components and reducers. The changes aim to ensure that frame-related operations are performed accurately and efficiently, while also enhancing the overall clarity and robustness of the codebase.

Changes

File Path Change Summary
changelog.d/..._fixed_propagation.md Fix for propagation mechanism in ground truth job to prevent creating copies on non-existing frames.
cvat-core/src/annotations-actions.ts Enhanced PropagateShapes class to dynamically determine frame numbers for propagation based on instance type. Updated method signatures for better type safety.
cvat-core/src/frames.ts Added getSegmentFrameNumbers method for computing segment frame numbers and integrated it into existing functions to streamline frame number retrieval.
cvat-core/src/object-utils.ts Updated propagateShapes function to accept an array of frame numbers, enhancing flexibility in shape propagation across multiple frames.
cvat-core/src/session-implementation.ts Modified Job and Task classes to include validation checks for frame indices and refined annotation methods for better error handling and validation.
cvat-core/src/session.ts Updated Session class methods to allow optional parameters for undo, redo, and log methods, enhancing flexibility in method calls.
cvat-ui/src/actions/annotation-actions.ts Modified propagateObjectAsync and getJobAsync functions to include checks for sessionInstance and improved frame number handling for jobs.
cvat-ui/src/components/.../propagate-confirm.tsx Refactored state management in PropagateConfirmComponent to improve clarity and type safety, including updates to input handlers.
cvat-ui/src/reducers/annotation-reducer.ts Enhanced state management by adding frameNumbers property to job state and updating reducer logic to reflect current job's frame information.
cvat-ui/src/reducers/index.ts Updated job interface in AnnotationState to include frameNumbers and modified queryParameters for more detailed job-related data.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant AnnotationService
    participant Job
    participant Task

    User->>UI: Initiate shape propagation
    UI->>AnnotationService: propagateObjectAsync(from, to)
    AnnotationService->>Job: Validate frame indices
    Job->>AnnotationService: Return valid frame numbers
    AnnotationService->>UI: Dispatch success action with frame numbers
    UI->>User: Display propagation result
Loading

🐇 "In the meadow where frames align,
Propagation flows, oh so fine!
With shapes that dance and numbers that play,
We hop through the frames, come what may.
A fix here, a tweak there, all in a row,
Hooray for the changes, let the good times flow!" 🐇


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using 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 do a full 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 configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

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: 11

🧹 Outside diff range and nitpick comments (9)
cvat-ui/src/components/annotation-page/standard-workspace/propagate-confirm.tsx (3)

103-106: Enhanced type safety in InputNumber onChange handler

The change to accept number | null and check for number type improves type safety. This prevents potential runtime errors from null inputs.

Consider using a default value or early return for null inputs to make the logic more explicit:

onChange={(value: number | null) => {
    if (value === null) return; // or use a default value
    updateTargetFrame(propagateDirection, value);
}}

Line range hint 143-153: Improved type safety and logic in second InputNumber onChange handler

The changes to accept number | null and the more detailed logic for setting the target frame are good improvements. They enhance type safety and handle different input scenarios more comprehensively.

For consistency with the earlier InputNumber, consider using an early return for null inputs:

onChange={(value: number | null) => {
    if (value === null) return;
    if (value > frameNumber) {
        setTargetFrame(clamp(value, frameNumber, stopFrame));
    } else if (value < frameNumber) {
        setTargetFrame(clamp(value, startFrame, frameNumber));
    } else {
        setTargetFrame(frameNumber);
    }
}}

Line range hint 1-159: Consider refactoring repeated clamp logic

The changes made improve type safety and state management consistently throughout the component. As a further improvement, consider refactoring the repeated clamp logic into a utility function to reduce code duplication and improve maintainability.

You could create a utility function like this:

const clampTargetFrame = (value: number, reference: number): number => {
    if (value > reference) {
        return clamp(value, reference, stopFrame);
    }
    if (value < reference) {
        return clamp(value, startFrame, reference);
    }
    return reference;
};

Then use it in both InputNumber onChange handlers:

onChange={(value: number | null) => {
    if (value === null) return;
    setTargetFrame(clampTargetFrame(value, frameNumber));
}}

This would make the code more DRY and easier to maintain.

cvat-core/src/session.ts (4)

375-375: LGTM! Consider documenting the default behavior.

The change to make the count parameter optional in the undo method is a good improvement, providing more flexibility in usage. Users can now call the method without explicitly specifying how many actions to undo.

Consider adding a comment or updating the documentation to clarify the default behavior when count is not provided. For example, does it undo one action by default?


376-376: LGTM! Consider documenting the default behavior.

The change to make the count parameter optional in the redo method is a good improvement, providing more flexibility in usage and consistency with the undo method.

Similar to the undo method, consider adding a comment or updating the documentation to clarify the default behavior when count is not provided. For example, does it redo one action by default?


405-406: LGTM! Consider documenting default values and behavior.

The changes to make the payload and wait parameters optional in the log method are good improvements, providing more flexibility in logging. Users can now call the method with only the required scope parameter if payload and wait are not needed.

Consider the following suggestions:

  1. Add comments or update documentation to clarify the default values or behavior when payload and wait are not provided.
  2. If applicable, consider using default parameter values in the method signature for clarity, e.g., payload: Parameters<typeof logger.log>[1] = {}.
  3. Ensure that the implementation of the log method handles these optional parameters correctly.

Line range hint 375-406: Overall improvements in API flexibility

The changes in this file enhance the flexibility of the Session class (and by extension, the Job and Task classes) by making certain method parameters optional. This includes:

  1. Making the count parameter optional for both undo and redo methods in the actions property.
  2. Making the payload and wait parameters optional for the log method in the logger property.

These modifications allow for more concise method calls when default behavior is desired, while still maintaining the option to specify these parameters when needed. This should improve the developer experience when working with these classes.

To further improve the codebase:

  1. Ensure that these changes are reflected in the documentation, including any default behaviors.
  2. Consider applying similar flexibility improvements to other parts of the API where it makes sense.
  3. If not already done, update any unit tests to cover both the cases where these parameters are provided and when they are omitted.
cvat-ui/src/actions/annotation-actions.ts (1)

467-469: Consider logging or handling when sessionInstance is undefined.

While throwing an error when sessionInstance is undefined prevents further execution, it might be helpful to log this event or provide additional context to aid in debugging.

Apply this diff to enhance error handling:

                 if (!sessionInstance) {
+                    console.error('SessionInstance is undefined in propagateObjectAsync.');
                     throw new Error('SessionInstance is not defined; propagation is not possible.');
                 }
cvat-core/src/session-implementation.ts (1)

883-883: Throw a more specific error

Instead of throwing a generic Error, consider creating and throwing a custom error or a more specific built-in error (e.g., NotImplementedError) to provide more context.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8c67070 and 86ae603.

📒 Files selected for processing (10)
  • changelog.d/20241016_133802_sekachev.bs_fixed_propagation.md (1 hunks)
  • cvat-core/src/annotations-actions.ts (2 hunks)
  • cvat-core/src/frames.ts (3 hunks)
  • cvat-core/src/object-utils.ts (2 hunks)
  • cvat-core/src/session-implementation.ts (1 hunks)
  • cvat-core/src/session.ts (2 hunks)
  • cvat-ui/src/actions/annotation-actions.ts (5 hunks)
  • cvat-ui/src/components/annotation-page/standard-workspace/propagate-confirm.tsx (4 hunks)
  • cvat-ui/src/reducers/annotation-reducer.ts (3 hunks)
  • cvat-ui/src/reducers/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • changelog.d/20241016_133802_sekachev.bs_fixed_propagation.md
🧰 Additional context used
🔇 Additional comments (12)
cvat-ui/src/components/annotation-page/standard-workspace/propagate-confirm.tsx (2)

26-34: Improved state management and frame handling

The refactoring of the useSelector hook and the derivation of startFrame and stopFrame from the frameNumbers array are good improvements. This approach centralizes state selection and makes the component more flexible to changes in frame numbering.

Also applies to: 36-38


Line range hint 125-132: Simplified Slider onChange handler

The change to accept an array of numbers instead of a tuple simplifies the code and makes it more flexible. The logic for determining which value to use is clear and correct.

cvat-ui/src/reducers/index.ts (2)

Line range hint 1-1186: Overall assessment of changes to AnnotationState

The modifications to the AnnotationState interface, specifically the job object, appear to be part of a larger feature implementation or enhancement related to frame handling and job initialization. The changes are type-safe and consistent with the existing code style.

To ensure a smooth integration of these changes:

  1. Review and update any components or reducers that interact with the job object in the AnnotationState.
  2. Update relevant documentation to reflect these new properties.
  3. If there are corresponding backend changes, ensure they align with these new frontend properties.
  4. Consider adding unit tests to cover scenarios involving these new properties.

Line range hint 727-733: New properties added to the job object in AnnotationState

The following changes have been made to the job object within the AnnotationState interface:

  1. A new frameNumbers property of type number[] has been added.
  2. New query parameters have been added to the queryParameters object:
    • defaultLabel of type string | null
    • defaultPointsCount of type number | null

These additions suggest enhancements in how frame data and job initialization are handled. Consider the following:

  1. Ensure that any components or functions that interact with the job object are updated to handle these new properties.
  2. Update any relevant documentation to reflect these changes.
  3. If there are corresponding changes in the backend or API, make sure they align with these new properties.

To verify the usage and impact of these new properties, please run the following script:

This script will help identify any places where these new properties are being used or where they might need to be implemented.

✅ Verification successful

Verification Successful: No Code Removals or Replacements Detected

The added properties frameNumbers, defaultLabel, and defaultPointsCount in cvat-ui/src/reducers/index.ts have been correctly integrated and are actively used throughout the codebase. No removed or replaced code was found in the specified lines.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of new job properties across the codebase

echo "Checking for frameNumbers usage:"
rg --type typescript "frameNumbers" ./cvat-ui/src

echo "\nChecking for defaultLabel usage:"
rg --type typescript "defaultLabel" ./cvat-ui/src

echo "\nChecking for defaultPointsCount usage:"
rg --type typescript "defaultPointsCount" ./cvat-ui/src

Length of output: 505


Script:

#!/bin/bash
# Description: Check for usage of new job properties across the codebase

echo "Checking for frameNumbers usage:"
rg -g "*.ts" -g "*.tsx" "frameNumbers" ./cvat-ui/src

echo ""

echo "Checking for defaultLabel usage:"
rg -g "*.ts" -g "*.tsx" "defaultLabel" ./cvat-ui/src

echo ""

echo "Checking for defaultPointsCount usage:"
rg -g "*.ts" -g "*.tsx" "defaultPointsCount" ./cvat-ui/src

Length of output: 7273

cvat-core/src/frames.ts (4)

214-217: LGTM: New method getSegmentFrameNumbers looks good.

The new getSegmentFrameNumbers method in the FramesMetaData class is a well-implemented addition. It correctly utilizes existing methods to convert data frame numbers to job-relative frame numbers, maintaining consistency with the current codebase structure.


356-356: Improvement: Simplified frame number calculation.

The use of the new getSegmentFrameNumbers method here improves code readability and maintainability. It encapsulates the frame number calculation logic, making the code more modular and easier to understand.


895-895: Improvement: Simplified getJobFrameNumbers function.

The getJobFrameNumbers function has been refactored to use the new getSegmentFrameNumbers method. This change reduces code duplication and improves consistency across the codebase. The functionality remains the same while the code becomes more maintainable.


214-217: Summary: Excellent refactoring for frame number handling.

The changes introduced in this file represent a well-executed refactoring of frame number handling. The new getSegmentFrameNumbers method in the FramesMetaData class centralizes the logic for converting between data frame numbers and job-relative frame numbers. This method is then consistently used throughout the file, including in the FrameData.prototype.data implementation and the getJobFrameNumbers function.

These changes result in:

  1. Improved code readability
  2. Reduced duplication of logic
  3. Better maintainability
  4. Consistent handling of frame numbers across different parts of the code

Overall, this refactoring enhances the quality of the codebase without introducing breaking changes or potential issues.

Also applies to: 356-356, 895-895

cvat-core/src/annotations-actions.ts (2)

110-110: ⚠️ Potential issue

Ensure method signature matches the base class for type safety

The method signature of run in PropagateShapes should match the base class BaseSingleFrameAction to ensure type safety and proper method overriding.

Consider updating the method signature to:

-public async run(
+public async run(
     instance: Job | Task,
     { collection: { shapes }, frameData: { number } },
 ): Promise<SingleFrameActionOutput> {

Alternatively, ensure that the base class method is correctly overridden.

Likely invalid or redundant comment.


117-117: ⚠️ Potential issue

Verify frame number range for Task instances to prevent off-by-one errors

When generating frame numbers for Task instances using range(0, instance.size), ensure that the frame numbering starts at 0 and ends at instance.size - 1. Since lodash's range function generates numbers up to, but not including, the end value, there is a potential for off-by-one errors if instance.size does not accurately represent the total number of frames.

Consider running the following script to verify that the frame numbers are correctly generated for Task instances:

✅ Verification successful

Frame Number Range Verified

The frame numbering for Task instances correctly starts at 0 and ends at instance.size - 1, preventing any off-by-one errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that frame numbers in Task instances start at 0 and end at (instance.size - 1)

# Test: Check the frame numbers for a Task instance
# Expected Result: Frame numbers should range from 0 to (instance.size - 1)

# Fetch all Task instances and display their sizes
rg --type typescript 'class Task' -A 20 | rg 'size'

# Verify the implementation of frame numbering in Task instances
rg --type typescript 'Task.prototype.frames' -A 20

Length of output: 172


Script:

#!/bin/bash
# Description: Verify that frame numbers in Task instances start at 0 and end at (instance.size - 1)

# Test: Check the frame numbers for a Task instance
# Expected Result: Frame numbers should range from 0 to (instance.size - 1)

# Fetch all Task instances and display their sizes
rg --glob '*.ts' 'class Task' -A 20 | rg 'size'

# Verify the implementation of frame numbering in Task instances
rg --glob '*.ts' 'Task.prototype.frames' -A 20

Length of output: 12909

cvat-core/src/object-utils.ts (1)

363-363: Ensure all usages of propagateShapes are updated to the new signature

The function propagateShapes now accepts frameNumbers: number[] instead of to: number. Please verify that all calls to this function throughout the codebase are updated accordingly to prevent any runtime errors.

cvat-ui/src/actions/annotation-actions.ts (1)

453-453: Ensure frameNumbers is available in the state before destructuring.

When destructuring frameNumbers from state.annotation.job, confirm that frameNumbers is initialized and populated to avoid potential undefined values.

@@ -107,13 +107,15 @@ class PropagateShapes extends BaseSingleFrameAction {
}

public async run(
instance,
instance: Job | Task,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure consistent parameter naming with the base class

In the run method of PropagateShapes, consider renaming the parameter instance to sessionInstance to maintain consistency with the base class BaseSingleFrameAction. This enhances readability and makes it easier for developers to follow the codebase.

@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT

import { omit, throttle } from 'lodash';
import { omit, range, throttle } from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Import only necessary functions to optimize bundle size

While importing range from lodash, consider importing only the specific functions you need to reduce the bundle size. This can be done by importing from lodash/range instead:

-import { omit, range, throttle } from 'lodash';
+import omit from 'lodash/omit';
+import range from 'lodash/range';
+import throttle from 'lodash/throttle';

This ensures that only the required modules are included, improving the performance of the application.

📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { omit, range, throttle } from 'lodash';
import omit from 'lodash/omit';
import range from 'lodash/range';
import throttle from 'lodash/throttle';

{ collection: { shapes }, frameData: { number } },
): Promise<SingleFrameActionOutput> {
if (number === this.#targetFrame) {
return { collection: { shapes } };
}
const propagatedShapes = propagateShapes<SerializedShape>(shapes, number, this.#targetFrame);

const frameNumbers = instance instanceof Job ? await instance.frames.frameNumbers() : range(0, instance.size);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using native JavaScript methods for generating ranges

Instead of using lodash's range function, you might use native JavaScript array methods to generate the range of frame numbers. This can reduce external dependencies and improve performance.

Example:

-const frameNumbers = instance instanceof Job ? await instance.frames.frameNumbers() : range(0, instance.size);
+const frameNumbers = instance instanceof Job 
+    ? await instance.frames.frameNumbers() 
+    : Array.from({ length: instance.size }, (_, i) => i);
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const frameNumbers = instance instanceof Job ? await instance.frames.frameNumbers() : range(0, instance.size);
const frameNumbers = instance instanceof Job
? await instance.frames.frameNumbers()
: Array.from({ length: instance.size }, (_, i) => i);

Comment on lines 401 to 403
for (const frame of frameNumbers) {
if (frame === from) {
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider filtering frameNumbers before the loop to exclude from

Currently, the loop checks if frame === from and uses continue to skip the iteration. For better readability and efficiency, consider filtering out the from frame from frameNumbers before entering the loop.

Apply this change:

 const states: T[] = [];
+ const targetFrames = frameNumbers.filter((frame) => frame !== from);
- for (const frame of frameNumbers) {
+ for (const frame of targetFrames) {
     // existing loop code
 }

Committable suggestion was skipped due to low confidence.

@@ -66,6 +66,7 @@ const defaultState: AnnotationState = {
groundTruthJobFramesMeta: null,
groundTruthInstance: null,
},
frameNumbers: [],
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure TypeScript interfaces include frameNumbers in job state

The addition of frameNumbers to the job state should be reflected in the TypeScript interfaces (AnnotationState and any related interfaces) to maintain type safety and prevent potential type errors.

@@ -205,6 +207,7 @@
job: {
...state.job,
openTime,
frameNumbers,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Validate frameNumbers before updating the state

Before assigning frameNumbers to the job state, consider validating that it is properly defined and contains the expected array of frame numbers to avoid any unexpected behavior.

Comment on lines +935 to +936
const jobMeta = await cvat.frames.getMeta('job', job.id);
const frameNumbers = await job.frames.frameNumbers();
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for external calls to getMeta and frameNumbers.

The calls to cvat.frames.getMeta('job', job.id) and job.frames.frameNumbers() may fail due to network issues or server errors, potentially causing unhandled exceptions. Consider wrapping these calls in try-catch blocks to handle possible errors gracefully and provide informative error messages.

Apply this diff to add error handling:

     const [job] = await cvat.jobs.get({ jobID });
+    let jobMeta;
+    let frameNumbers;
+    try {
+        jobMeta = await cvat.frames.getMeta('job', job.id);
+        frameNumbers = await job.frames.frameNumbers();
+    } catch (error) {
+        throw new Error(`Failed to retrieve job metadata or frame numbers: ${error.message}`);
+    }
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const jobMeta = await cvat.frames.getMeta('job', job.id);
const frameNumbers = await job.frames.frameNumbers();
let jobMeta;
let frameNumbers;
try {
jobMeta = await cvat.frames.getMeta('job', job.id);
frameNumbers = await job.frames.frameNumbers();
} catch (error) {
throw new Error(`Failed to retrieve job metadata or frame numbers: ${error.message}`);
}

Comment on lines 471 to 473
const framesToPropagate = frameNumbers.filter(
(frameNumber: number) => frameNumber >= Math.min(from, to) && frameNumber <= Math.max(from, to),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Verify that frameNumbers is defined and not empty before filtering.

When filtering frameNumbers to obtain framesToPropagate, ensure that frameNumbers is defined and contains frame numbers. If frameNumbers is undefined or empty, framesToPropagate will also be undefined or empty, which may lead to unexpected behavior.

Apply this diff to add a check:

                 const framesToPropagate = frameNumbers.filter(
                     (frameNumber: number) => frameNumber >= Math.min(from, to) && frameNumber <= Math.max(from, to),
                 );
+                if (!framesToPropagate.length) {
+                    throw new Error('No frames available for propagation.');
+                }

Committable suggestion was skipped due to low confidence.

cvat-ui/src/actions/annotation-actions.ts Show resolved Hide resolved
cvat-core/src/session-implementation.ts Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.30%. Comparing base (a4a989d) to head (60b2693).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8550      +/-   ##
===========================================
+ Coverage    74.28%   74.30%   +0.02%     
===========================================
  Files          401      401              
  Lines        43405    43419      +14     
  Branches      3945     3951       +6     
===========================================
+ Hits         32242    32262      +20     
+ Misses       11163    11157       -6     
Components Coverage Δ
cvat-ui 78.64% <85.71%> (+0.04%) ⬆️
cvat-server 70.58% <ø> (ø)

Copy link

sonarcloud bot commented Nov 1, 2024

@bsekachev bsekachev merged commit ceba1b7 into develop Nov 1, 2024
34 checks passed
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.

2 participants