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

Job validations (public part) #8321

Merged
merged 10 commits into from
Aug 23, 2024
Merged

Job validations (public part) #8321

merged 10 commits into from
Aug 23, 2024

Conversation

zhiltsov-max
Copy link
Contributor

@zhiltsov-max zhiltsov-max commented Aug 19, 2024

Motivation and context

  • Added max_validations_per_job, target_metric, target_metric_threshold fields in quality settings
  • Added assignee_last_updated in quality reports
  • Added separate accuracy, precision, and recall fields in quality summary
  • Refactored some IAM code

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

    • Enhanced permission handling for jobs, tasks, and projects, streamlining the creation process.
    • Introduced new quality control metrics and settings, enabling more granular tracking and reporting.
  • Bug Fixes

    • Improved validation logic to enforce constraints on job validation attempts.
  • Documentation

    • Added descriptive help texts for new fields in quality report serializers, clarifying their purpose.
  • Chores

    • Updated method signatures to improve flexibility and maintainability across permission handling and reporting functionalities.

Copy link
Contributor

coderabbitai bot commented Aug 19, 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 recent changes enhance the permission handling and quality control features within the application. Key modifications include simplifying the permission generation process by removing unnecessary context retrieval steps, enriching models with new fields for improved quality metrics, and updating serializers for better data validation. These improvements streamline workflows, enhance functionality, and ensure more accurate reporting and permissions management.

Changes

Files Change Summary
cvat/apps/analytics_report/permissions.py Simplified permission generation by removing iam_context retrieval; directly utilizes the request object for jobs, tasks, and projects.
cvat/apps/engine/permissions.py Updated create_scope_view methods to accept request and allow for more flexible input types (int or object) for projects and jobs; improved context handling.
cvat/apps/quality_control/migrations/0003_... Added new fields to QualityReport and QualitySettings models, enhancing tracking and configuration of quality metrics.
cvat/apps/quality_control/models.py Introduced QualityTargetMetricType enum and added new fields to models for tracking quality metrics and settings.
cvat/apps/quality_control/quality_reports.py Enhanced _compute_reports and _save_reports methods with new parameter for assignee_last_updated, improving report traceability.
cvat/apps/quality_control/serializers.py Updated serializers to include new fields for quality metrics and improved validation logic for job validation settings.
cvat/apps/webhooks/permissions.py Changed parameters for create_scope_view in ProjectPermission to include the request object, adjusting how permissions are created.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Webhook
    participant Permissions
    participant QualityControl

    User->>Webhook: Request project access
    Webhook->>Permissions: create_scope_view(request, project_id)
    Permissions-->>Webhook: Return permissions
    Webhook-->>User: Permissions granted

    User->>QualityControl: Submit quality report
    QualityControl->>QualityControl: Validate report
    QualityControl-->>User: Report saved with metrics
Loading

🐇 In the code of quality, we hop and dance,
With metrics and fields, we take a chance.
Permissions simplified, like a breeze in spring,
Enhancing our tools, oh what joy they bring!
A tale of rabbits, in code we delight,
Hopping through changes, all feels just right! 🐰✨


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.
    • @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 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 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.

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

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

Outside diff range, codebase verification and nitpick comments (1)
cvat/apps/quality_control/serializers.py (1)

103-110: Ensure help texts are clear and accurate.

The help texts for the new fields provide guidance on their usage. Ensure that these descriptions are clear and align with the application's functionality.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between afbb143 and c0f0d2f.

Files selected for processing (7)
  • cvat/apps/analytics_report/permissions.py (2 hunks)
  • cvat/apps/engine/permissions.py (3 hunks)
  • cvat/apps/quality_control/migrations/0003_qualityreport_assignee_last_updated_and_more.py (1 hunks)
  • cvat/apps/quality_control/models.py (3 hunks)
  • cvat/apps/quality_control/quality_reports.py (4 hunks)
  • cvat/apps/quality_control/serializers.py (4 hunks)
  • cvat/apps/webhooks/permissions.py (1 hunks)
Additional comments not posted (18)
cvat/apps/quality_control/migrations/0003_qualityreport_assignee_last_updated_and_more.py (4)

14-18: Ensure assignee_last_updated field is initialized correctly.

The assignee_last_updated field is added as a DateTimeField with null=True. Ensure that this field is correctly initialized in existing records to avoid potential null-related issues.


24-35: Validate choices for target_metric.

The target_metric field uses choices from QualityTargetMetricType. Ensure these choices are correctly utilized in the application logic.


19-23: Review max_validations_per_job default value.

The max_validations_per_job field is added with a default value of 0. Ensure this aligns with the intended logic for job validations.

Verification successful

Default Value of max_validations_per_job is Appropriate

The default value of 0 for the max_validations_per_job field is consistent with the intended logic. It aligns with the validation logic in the serializers, ensuring the field is non-negative and properly described as limiting validation attempts. This setup appears to be intentional and correctly implemented.

  • cvat/apps/quality_control/serializers.py: Validation ensures max_validations_per_job is non-negative.
  • cvat/apps/quality_control/models.py: Default value set to 0.
Scripts executed

The following scripts were executed for the analysis:

Script:

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

# Test: Search for the usage of `max_validations_per_job`. Expect: Proper handling of the default value.
rg --type python 'max_validations_per_job'

Length of output: 73


Script:

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

# Test: Search for the usage of `max_validations_per_job`. Expect: Proper handling of the default value.
rg 'max_validations_per_job' --glob '*.py' -A 3

Length of output: 2003


37-41: Check target_metric_threshold default value.

The target_metric_threshold field is added with a default value of 0.7. Ensure this default aligns with the quality control requirements.

cvat/apps/engine/permissions.py (2)

308-318: LGTM! But verify the function usage in the codebase.

The changes enhance the method's flexibility and robustness.

However, ensure that all function calls to create_scope_view in ProjectPermission match the new signature.

Verification successful

All usages of create_scope_view match the new signature.

The function calls in the following files are consistent with the updated method signature:

  • cvat/apps/webhooks/permissions.py
  • cvat/apps/engine/permissions.py
  • cvat/apps/analytics_report/permissions.py

No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `create_scope_view` in `ProjectPermission` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 "ProjectPermission.create_scope_view"

Length of output: 90


Script:

#!/bin/bash
# Description: Verify all function calls to `create_scope_view` in `ProjectPermission` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 "ProjectPermission.create_scope_view"

Length of output: 1594


692-702: LGTM! But verify the function usage in the codebase.

The changes enhance the method's flexibility and robustness.

However, ensure that all function calls to create_scope_view in JobPermission match the new signature.

Verification successful

Function usage matches the new signature.

The create_scope_view method in JobPermission is correctly used with the new signature in the codebase.

  • cvat/apps/analytics_report/permissions.py: Correct usage observed.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `create_scope_view` in `JobPermission` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type python -A 5 "JobPermission.create_scope_view"

Length of output: 86


Script:

#!/bin/bash
# Description: Verify all function calls to `create_scope_view` in `JobPermission` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type py -A 5 "JobPermission.create_scope_view"

Length of output: 1199

cvat/apps/quality_control/quality_reports.py (2)

Line range hint 2305-2318: Approved: Addition of assignee_last_updated.

The inclusion of the assignee_last_updated parameter enhances the tracking of report updates and is well-integrated into the method.


Line range hint 2425-2438: Approved: Addition of assignee_last_updated.

The inclusion of the assignee_last_updated parameter enhances the data stored in reports and is well-integrated into the method.

cvat/apps/analytics_report/permissions.py (3)

37-37: Ensure correct handling of job_id parameter.

The job_id is retrieved from query parameters or request data, depending on the action. Verify that both sources are correctly handled throughout the application.

Verification successful

The job_id parameter is correctly handled. The retrieval and use of job_id from both query parameters and request data are implemented as expected in the cvat/apps/analytics_report/permissions.py file. No issues were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify handling of `job_id` in the application.

# Test: Search for occurrences of `job_id` retrieval. Expect: Correct handling in both query parameters and request data.
rg --type python -A 3 $'job_id = request.query_params.get("job_id")|job_id = request.data.get("job_id")'

Length of output: 136


Script:

#!/bin/bash
# Description: Verify handling of `job_id` in the application.

# Test: Search for occurrences of `job_id` retrieval. Expect: Correct handling in both query parameters and request data.
rg -t py -A 3 'job_id = request.query_params.get("job_id")|job_id = request.data.get("job_id")'

Length of output: 97


Script:

#!/bin/bash
# Description: Broaden the search for `job_id` to understand its usage and retrieval in the codebase.

# Test: Search for any occurrences of `job_id` to see how it is being used and retrieved.
rg -t py -A 3 'job_id'

Length of output: 101647


53-53: Confirm project_id handling consistency.

Ensure that project_id is consistently handled across the application, especially in permissions logic.

Verification successful

project_id Handling is Consistent Across the Application

The handling of project_id appears to be consistent across the application, especially within the permissions logic. The parameter is retrieved and used in a similar manner in various parts of the codebase, indicating a standardized approach. No inconsistencies were found in its handling.

  • project_id is retrieved from both request.query_params and request.data.
  • It is used in various contexts, such as function calls and validations, across different files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify handling of `project_id` in the application.

# Test: Search for occurrences of `project_id` retrieval and usage. Expect: Consistent logic across the application.
rg --type python -A 3 $'project_id = request.query_params.get("project_id")|project_id = request.data.get("project_id")'

Length of output: 152


Script:

#!/bin/bash
# Description: Verify handling of `project_id` in the application.

# Test: Search for occurrences of `project_id` retrieval and usage. Expect: Consistent logic across the application.
rg -A 3 $'project_id = request.query_params.get("project_id")|project_id = request.data.get("project_id")'

Length of output: 107


Script:

#!/bin/bash
# Description: Broaden the search for `project_id` handling in the application.

# Test: Search for occurrences of `project_id` being assigned or used in any context.
rg -A 3 'project_id\s*='

Length of output: 48208


49-49: Verify the integrity of task_id retrieval.

Ensure that task_id is correctly derived from job.segment.task.id and that this logic is consistent with the rest of the application.

Verification successful

Integrity of task_id retrieval is consistent within permissions.py

The retrieval of task_id from job.segment.task.id is consistent within the cvat/apps/analytics_report/permissions.py file. The logic checks if task_id is truthy before using it, ensuring its integrity in this context. If further verification is needed across the application, manual inspection or additional searches may be required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify retrieval and usage of `task_id` in the application.

# Test: Search for occurrences of `task_id` retrieval from `job.segment.task.id`. Expect: Consistent logic across the application.
rg --type python -A 3 $'task_id = job.segment.task.id'

Length of output: 86


Script:

#!/bin/bash
# Description: Verify retrieval and usage of `task_id` in the application.

# Corrected Test: Search for occurrences of `task_id` retrieval from `job.segment.task.id`. Expect: Consistent logic across the application.
rg 'task_id = job.segment.task.id' --glob '*.py' -A 3

Length of output: 389

cvat/apps/webhooks/permissions.py (1)

42-42: Verify create_scope_view method update.

Ensure that the create_scope_view method in ProjectPermission correctly handles the newly added request parameter and that this change is reflected in all relevant parts of the application.

cvat/apps/quality_control/serializers.py (3)

42-44: New metrics fields added to QualityReportSummarySerializer.

The addition of accuracy, precision, and recall fields enhances the quality assessment capabilities. Ensure that these fields are correctly populated and used in the application.


79-81: New fields added to QualitySettingsSerializer.

The fields target_metric, target_metric_threshold, and max_validations_per_job provide more control over quality settings. Verify that these fields are correctly integrated into the application logic.


161-163: Validation logic for max_validations_per_job.

The validation logic ensures that max_validations_per_job is not negative. This is a good practice to prevent invalid data entry.

cvat/apps/quality_control/models.py (3)

72-83: New QualityTargetMetricType enum added.

This enum introduces metrics for quality assessment. Ensure that these metrics are used consistently across the application.


105-105: New assignee_last_updated field in QualityReport.

This field tracks the last update to the assignee. Verify that this field is updated appropriately in the application logic.


221-229: New fields in QualitySettings.

The fields target_metric, target_metric_threshold, and max_validations_per_job enhance the configurability of quality settings. Ensure these fields are integrated into the application's quality control processes.

try:
project = Project.objects.get(id=project)
except Project.DoesNotExist as ex:
raise ValidationError(str(ex))

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
try:
job = Job.objects.get(id=job)
except Job.DoesNotExist as ex:
raise ValidationError(str(ex))

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
@codecov-commenter
Copy link

codecov-commenter commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 87.80488% with 5 lines in your changes missing coverage. Please review.

Project coverage is 83.58%. Comparing base (c5ff8bc) to head (3ce0864).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8321   +/-   ##
========================================
  Coverage    83.57%   83.58%           
========================================
  Files          393      393           
  Lines        41578    41594   +16     
  Branches      3841     3841           
========================================
+ Hits         34749    34765   +16     
  Misses        6829     6829           
Components Coverage Δ
cvat-ui 79.64% <ø> (ø)
cvat-server 87.06% <87.80%> (+<0.01%) ⬆️

@klakhov klakhov mentioned this pull request Aug 21, 2024
4 tasks
cvat/schema.yml Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Aug 23, 2024

@zhiltsov-max zhiltsov-max merged commit d9a525b into develop Aug 23, 2024
33 checks passed
@klakhov klakhov mentioned this pull request Aug 26, 2024
7 tasks
@zhiltsov-max zhiltsov-max mentioned this pull request Aug 26, 2024
7 tasks
@cvat-bot cvat-bot bot mentioned this pull request Aug 27, 2024
@bsekachev bsekachev deleted the zm/validation-api branch August 29, 2024 08:02
bschultz96 pushed a commit to bschultz96/cvat that referenced this pull request Sep 12, 2024
<!-- Raise an issue to propose your change
(https://github.com/cvat-ai/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution guide](https://docs.cvat.ai/docs/contributing/).
-->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->

- Added `max_validations_per_job`, `target_metric`,
`target_metric_threshold` fields in quality settings
- Added `assignee_last_updated` in quality reports
- Added separate `accuracy`, `precision`, and `recall` fields in quality
summary
- Refactored some IAM code

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [ ] I submit my changes into the `develop` branch
- [ ] I have created a changelog fragment <!-- see top comment in
CHANGELOG.md -->
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [ ] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/cvat-ai/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/cvat-ai/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/cvat-ai/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/cvat-ai/cvat/tree/develop/cvat-ui#versioning))

### License

- [ ] I submit _my code changes_ under the same [MIT License](
https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced permission handling for jobs, tasks, and projects,
streamlining the creation process.
- Introduced new quality control metrics and settings, enabling more
granular tracking and reporting.

- **Bug Fixes**
- Improved validation logic to enforce constraints on job validation
attempts.

- **Documentation**
- Added descriptive help texts for new fields in quality report
serializers, clarifying their purpose.

- **Chores**
- Updated method signatures to improve flexibility and maintainability
across permission handling and reporting functionalities.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Sep 25, 2024
7 tasks
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.

4 participants