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

refactor: improve NotFoundError exceptions raised on API v1 and how records are retrieved from database #4876

Conversation

jfcalvo
Copy link
Member

@jfcalvo jfcalvo commented May 24, 2024

Description

This is the first of some PRs refactoring and improving the error handling for API v1.

In this specific PR I'm improving how NotFoundError is managed in the API v1 with the following changes:

  • Now NotFoundError is added to the list of the captures exceptions for API v1.
  • The response for NotFoundError is not changed using the same structure: {"detail": "message"}. Once we are working on v2.0 we can change it to use the new one.
  • I have added two new methods to our database models so the retrieval of instances is simplified:
    • get: useful to get an instance of a database model using an id.
    • get_or_raise: useful to get an instance of a database model using an id and raising a NotFoundError exception if the instance is not found.
    • The two methods include a options parameter that can be used to pre-load associations.

Refs #4871

Type of change

(Please delete options that are not relevant. Remember to title the PR according to the type of change)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (change restructuring the codebase without changing functionality)
  • Improvement (change adding some improvement to an existing functionality)
  • Documentation update

How Has This Been Tested

(Please describe the tests that you ran to verify your changes. And ideally, reference tests)

  • Changing tests and adding new ones when necessary.

Checklist

  • I added relevant documentation
  • follows the style guidelines of this project
  • I did a self-review of my code
  • I made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I filled out the contributor form (see text above)
  • I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)

@jfcalvo jfcalvo requested a review from frascuchon May 24, 2024 16:09
Copy link

codecov bot commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.90%. Comparing base (c701642) to head (2da4283).

Additional details and impacted files
@@                            Coverage Diff                             @@
##           refactor/improve-api-v1-error-handling    #4876      +/-   ##
==========================================================================
- Coverage                                   90.95%   90.90%   -0.05%     
==========================================================================
  Files                                         206      206              
  Lines                                       10094    10021      -73     
==========================================================================
- Hits                                         9181     9110      -71     
+ Misses                                        913      911       -2     
Flag Coverage Δ
argilla-server 90.90% <100.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jfcalvo jfcalvo merged commit 1ac1e18 into refactor/improve-api-v1-error-handling May 27, 2024
8 checks passed
@jfcalvo jfcalvo deleted the refactor/improve-api-v1-not-found-errors branch May 27, 2024 11:13
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