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: Re-newed import/export request failed immediately if the previous failed #8649

Merged
merged 7 commits into from
Nov 7, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Nov 6, 2024

Motivation and context

Depends on #8648

To reproduce import annotations to a job for example:

First import must be failed (e.g. wrong archive structure)
Second import must have correct data, but also will be failed

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

  • New Features

    • Introduced enhanced import/export functionality, allowing for better handling of requests and progress updates.
    • Added new functions for importing datasets and backups with improved parameter handling.
    • Added a new export, StorageLocation, expanding the API surface.
  • Bug Fixes

    • Resolved issues preventing successful retries of import/export requests after failures.
    • Fixed an error related to accessing undefined properties, improving application stability.
  • Documentation

    • Added comments to clarify the purpose and usage of new functions in import/export actions.
  • Style

    • Minor formatting improvements for better readability in the codebase.

@bsekachev bsekachev requested a review from nmanovic as a code owner November 6, 2024 09:30
Copy link
Contributor

coderabbitai bot commented Nov 6, 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

This pull request includes several updates aimed at fixing errors and enhancing functionality within the application. Key changes involve resolving specific error handling issues, restructuring import and export functionalities, and modifying the RequestsManager class to ensure proper promise handling. New methods for dataset and backup imports/exports have been introduced, and existing methods have been updated for improved clarity and maintainability. Additionally, a new export, StorageLocation, has been added to the core wrapper.

Changes

File Path Change Summary
changelog.d/20241106_095739_sekachev.bs_fixed_exception_1.md Fixed error related to 'Cannot read properties of undefined (reading 'push')'.
changelog.d/20241106_112907_sekachev.bs_fixed_exception_2.md Resolved issue with import/export request handling for retries after a failure.
cvat-core/src/requests-manager.ts Changed promise property from optional to required in RequestsManager; modified promise handling in listen method.
cvat-ui/src/actions/export-actions.ts Updated exportDatasetAsync and added exportBackupAsync; restructured export logic and error handling.
cvat-ui/src/actions/import-actions.ts Replaced listenImportDatasetAsync with importDatasetAsync; added importBackupAsync and improved import logic.
cvat-ui/src/actions/requests-actions.ts Minor formatting change in the listen function for improved readability.
cvat-ui/src/cvat-core-wrapper.ts Added new export StorageLocation from cvat-core/src/enums.

Poem

🐇 In the code where bunnies play,
Fixes made to save the day.
Exports and imports dance in line,
With promises that now align.
Hooray for changes, bright and new,
A happy hop for me and you! 🌟


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

🧹 Outside diff range and nitpick comments (8)
cvat-core/src/requests-manager.ts (1)

135-138: Consider adding error logging

While the error handling is correct, consider adding error logging to help with debugging production issues.

                        }
+                       console.error(`Request ${requestID} failed:`, error);
                        delete this.listening[requestID];
                        reject(error);
cvat-ui/src/actions/export-actions.ts (1)

28-29: Consider moving the core initialization to a centralized location.

Initializing the core object directly in this file may lead to inconsistencies if it is being initialized in multiple places. Consider moving the initialization to a centralized location and importing it where needed.

cvat-ui/src/actions/import-actions.ts (6)

72-74: Fix JSDoc comment formatting

The JSDoc comment has an extra asterisk, which may cause formatting issues with documentation tools.

Apply this diff to correct the comment:

-/** *
+/**
 * Function is supposed to be used when a new dataset import request initiated by a user
-** */
+ */

87-90: Use the existing listen helper function

Instead of defining a local listenForImport function, consider using the listen helper function imported from ./requests-actions for consistency and to reduce redundancy.

Apply this diff to use the listen function:

-        const listenForImport = (rqID: string) => core.requests.listen(rqID, {
-            callback: (updatedRequest) => updateRequestProgress(updatedRequest, dispatch),
-        });
-
...
-            await listenForImport(rqID);
+            await listen(rqID, dispatch);

163-165: Fix JSDoc comment formatting

The JSDoc comment for importBackupAsync has an extra asterisk at the beginning and end.

Apply this diff to correct the comment:

-/** *
+/**
 * Function is supposed to be used when a new backup import request initiated by a user
-** */
+ */

171-174: Use the listen helper function for consistency

In importBackupAsync, you're using core.requests.listen directly. For consistency with other parts of the code, consider using the listen helper function.

Apply this diff to use the listen function:

-                const result = await core.requests.listen(rqID, {
-                    callback: (updatedRequest) => updateRequestProgress(updatedRequest, dispatch),
-                });
+                const result = await listen(rqID, dispatch);

182-184: Fix JSDoc comment formatting

The JSDoc comment for listenImportBackupAsync contains extra asterisks.

Apply this diff to correct the comment:

-/** *
+/**
 * Function is supposed to be used when application starts listening to existing backup import request
-** */
+ */

201-203: Fix JSDoc comment formatting

The JSDoc comment for listenImportDatasetAsync has formatting issues due to extra asterisks.

Apply this diff to correct the comment:

-/** *
+/**
 * Function is supposed to be used when application starts listening to existing dataset import request
-** */
+ */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6a60642 and 3efcb71.

📒 Files selected for processing (7)
  • changelog.d/20241106_095739_sekachev.bs_fixed_exception_1.md (1 hunks)
  • changelog.d/20241106_112907_sekachev.bs_fixed_exception_2.md (1 hunks)
  • cvat-core/src/requests-manager.ts (3 hunks)
  • cvat-ui/src/actions/export-actions.ts (4 hunks)
  • cvat-ui/src/actions/import-actions.ts (5 hunks)
  • cvat-ui/src/actions/requests-actions.ts (1 hunks)
  • cvat-ui/src/cvat-core-wrapper.ts (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • changelog.d/20241106_095739_sekachev.bs_fixed_exception_1.md
  • cvat-ui/src/actions/requests-actions.ts
🔇 Additional comments (11)
cvat-ui/src/cvat-core-wrapper.ts (2)

31-31: LGTM! Clean addition of StorageLocation enum import

The StorageLocation enum is properly imported alongside related enums, maintaining consistent code organization.


112-112: LGTM! Verify StorageLocation enum usage

The StorageLocation enum is properly exported. Let's verify its usage across the codebase to ensure it's properly integrated with the export functionality.

✅ Verification successful

Based on the search results, I can now generate the final response since I have comprehensive information about the StorageLocation enum usage across the codebase:

StorageLocation enum is properly integrated with export functionality

The StorageLocation enum is correctly used throughout the codebase for handling storage locations in:

  • Core functionality (cvat-core)
  • UI components for export/import operations
  • Project/task creation flows
  • Backup/restore operations

The enum is consistently used with two values (LOCAL and CLOUD_STORAGE) and properly integrated with:

  • Storage class implementation
  • Server communication layer
  • UI storage selection components
  • Export/backup workflows
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of StorageLocation enum in the codebase
# Expected: Find usage in export-related functionality, particularly with targetStorage parameter

# Search for StorageLocation usage
echo "=== StorageLocation Usage ==="
rg "StorageLocation" -A 3

# Search for targetStorage parameter usage
echo -e "\n=== targetStorage Parameter Usage ==="
rg "targetStorage" -A 3

Length of output: 97767

cvat-core/src/requests-manager.ts (2)

37-37: LGTM: Type safety improvement

Making the promise property required instead of optional is a good change that ensures better type safety and reflects the actual usage in the code.


142-155: LGTM: Improved promise handling

Moving the promise initialization to a microtask and handling failed initial requests immediately are good improvements that:

  1. Fix the race condition in promise initialization
  2. Address the core issue where renewed requests failed immediately after a previous failure
  3. Ensure proper cleanup of resources
cvat-ui/src/actions/export-actions.ts (6)

117-141: LGTM!

The new exportBackupAsync function looks good. It follows a similar structure to exportDatasetAsync and handles the progress updates and error cases appropriately.


170-190: LGTM!

The new listenExportBackupAsync function looks good. It correctly handles the instance type and dispatches the appropriate actions based on the result of the listen function.


81-91: Ensure proper error handling and user feedback for new parameters.

The exportDatasetAsync function now includes new parameters: useDefaultSettings, targetStorage, and an optional name. Make sure to handle any potential errors or edge cases related to these new parameters and provide appropriate user feedback.

Run the following script to verify error handling:

#!/bin/bash
# Description: Verify error handling for new parameters in `exportDatasetAsync`.

# Test: Search for error handling code related to the new parameters.
# Expect: Proper error handling and user feedback for edge cases.
ast-grep --pattern $'exportDatasetAsync($_, $_, $_, useDefaultSettings, targetStorage, name) {
  $$$
}'

99-107: Verify the behavior of the listen function.

The listen function from core.requests is being used to handle the progress updates for the export request. Please ensure that this function behaves as expected and dispatches the correct actions based on the request status.

Run the following script to verify the behavior of the listen function:

#!/bin/bash
# Description: Verify the behavior of the `listen` function.

# Test: Search for the usage of the `listen` function.
# Expect: Correct actions being dispatched based on the request status.
ast-grep --pattern $'core.requests.listen($_, {
  $$$
})'

143-168: Verify the behavior of the updated listenExportDatasetAsync function.

The listenExportDatasetAsync function has been updated to align with the changes in exportDatasetAsync. Please ensure that it correctly dispatches the success or failure actions based on the result of the listen function.

Run the following script to verify the behavior of listenExportDatasetAsync:

#!/bin/bash
# Description: Verify the behavior of the updated `listenExportDatasetAsync` function.

# Test: Search for the usage of `listenExportDatasetAsync`.
# Expect: Correct actions being dispatched based on the result of the `listen` function.
ast-grep --pattern $'listenExportDatasetAsync($_, $_, {
  $$$
})'

8-9: Verify the usage of StorageLocation in the codebase.

The new StorageLocation export from cvat-core-wrapper is being used in this file. Please ensure that it is being used consistently and correctly throughout the codebase.

Run the following script to verify the usage of StorageLocation:

✅ Verification successful

The usage of StorageLocation is consistent and correctly implemented across the codebase

The verification shows that StorageLocation is properly used throughout the codebase:

  1. It's correctly defined as an enum in both cvat-core/src/enums.ts and cvat-ui/src/reducers/index.ts
  2. It's consistently used in storage-related components for handling both local and cloud storage locations
  3. The import in export-actions.ts aligns with its usage in:
    • Storage management components
    • Import/Export modals
    • Task and Project creation forms
    • Request handling

The type is properly integrated into the storage management system and follows a consistent pattern across all implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `StorageLocation` in the codebase.

# Test: Search for the usage of `StorageLocation`. 
# Expect: Consistent and correct usage across the codebase.
rg -A 5 $'StorageLocation'

Length of output: 748


Script:

#!/bin/bash
# Let's try a different approach to search for StorageLocation usage

# Search for StorageLocation in import statements
rg "import.*StorageLocation" -A 2

# Search for type annotations or usage of StorageLocation
rg "\bStorageLocation\b" -A 2

# Search for files that might be using StorageLocation
fd -e ts -e tsx -x grep -l "StorageLocation" {}

Length of output: 39201

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

14-15: Imports are correctly added

The new imports from ./requests-actions are appropriate and necessary for the updated functionality.

Comment on lines 1 to 4
### Fixed

- Re-newed import/export request failed immediately if the previous failed
(<https://github.com/cvat-ai/cvat/pull/XXXX>)
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 6, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update the PR link in the changelog entry.

The changelog entry follows the correct format and provides a clear description of the fix. However, the PR link needs to be updated.

Apply this diff to fix the PR link:

- (<https://github.com/cvat-ai/cvat/pull/XXXX>)
+ (<https://github.com/cvat-ai/cvat/pull/8649>)
📝 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
### Fixed
- Re-newed import/export request failed immediately if the previous failed
(<https://github.com/cvat-ai/cvat/pull/XXXX>)
### Fixed
- Re-newed import/export request failed immediately if the previous failed
(<https://github.com/cvat-ai/cvat/pull/8649>)

Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update link

Copy link
Contributor

Choose a reason for hiding this comment

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

@klakhov Yes, please update the link in the changelog entry to point to the correct PR. Replace XXXX with 8649 in the link. Here is the updated entry:

### Fixed

- Re-newed import/export request failed immediately if the previous failed
  (<https://github.com/cvat-ai/cvat/pull/8649>)

Comment on lines 96 to 131
const rqID = await (instance as Project).annotations.importDataset(
format,
useDefaultSettings,
sourceStorage,
file,
{
convMaskToPoly,
updateStatusCallback: (message: string, progress: number) => (
dispatch(importActions.importDatasetUpdateStatus(
instance, Math.floor(progress * 100), message,
))
),
});
if (shouldListenForProgress(rqID, state.requests)) {
await listen(rqID, dispatch);
}
},
);

await listenForImport(rqID);
} else if (instanceType === 'task') {
dispatch(importActions.importDataset(instance, format));
const rqID = await (instance as Task).annotations
.upload(format, useDefaultSettings, sourceStorage, file, {
convMaskToPoly,
});
if (shouldListenForProgress(rqID, state.requests)) {
await listen(rqID, dispatch);
}
const rqID = await (instance as Task).annotations.upload(
format,
useDefaultSettings,
sourceStorage,
file,
{ convMaskToPoly },
);
await listenForImport(rqID);
} else { // job
dispatch(importActions.importDataset(instance, format));
const rqID = await (instance as Job).annotations
.upload(format, useDefaultSettings, sourceStorage, file, {
convMaskToPoly,
});
const rqID = await (instance as Job).annotations.upload(
format,
useDefaultSettings,
sourceStorage,
file,
{ convMaskToPoly },
);

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

Refactor to eliminate code duplication

The importDatasetAsync function contains similar code blocks for handling project, task, and job instances. Consider refactoring to reduce duplication and improve maintainability.

You could abstract the common logic into a separate function or unify the handling of different instance types.

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 62.16216% with 28 lines in your changes missing coverage. Please review.

Project coverage is 74.29%. Comparing base (7f764a2) to head (08a85e6).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8649      +/-   ##
===========================================
- Coverage    74.37%   74.29%   -0.09%     
===========================================
  Files          401      401              
  Lines        43422    43420       -2     
  Branches      3951     3943       -8     
===========================================
- Hits         32297    32258      -39     
- Misses       11125    11162      +37     
Components Coverage Δ
cvat-ui 78.62% <62.16%> (-0.19%) ⬇️
cvat-server 70.58% <ø> (ø)

Comment on lines 1 to 4
### Fixed

- Re-newed import/export request failed immediately if the previous failed
(<https://github.com/cvat-ai/cvat/pull/XXXX>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update link

@bsekachev
Copy link
Member Author

@klakhov

Applied comments

Copy link

sonarqubecloud bot commented Nov 7, 2024

@bsekachev bsekachev merged commit 1fd1175 into develop Nov 7, 2024
34 checks passed
@bsekachev bsekachev deleted the bs/fixed_exception_2 branch November 8, 2024 13:40
@cvat-bot cvat-bot bot mentioned this pull request Nov 11, 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.

3 participants