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

Move from flask_restful to flask_restx. Replace error dictionaries with abort #15

Merged
merged 8 commits into from
Jun 17, 2024

Conversation

maxachis
Copy link

@maxachis maxachis commented May 25, 2024

Fixes

Description

  • Replaces all instances of returning error dictionaries with flask_restx.abort in multiple resources files. This refactoring enhances code readability and simplifies error handling. It also ensures that HTTP errors are handled in a more standardized way across the application.
  • Resource class and Api usage in app.py has transitioned from flask_restful to flask_restx, which supports automated swagger documentation and has more active support.

Testing

  • None. Testing will be encompassed in expanded tests for all modules.

Performance

  • No expected performance impact.

Docs

  • Not applicable.

maxachis added 3 commits May 25, 2024 19:08
This commit replaces all instances of returning error dictionaries with flask_restx.abort in multiple resources files. This refactoring enhances code readability and simplifies error handling. It also ensures that HTTP errors are handled in a more standardized way across the application.
The flask_restful import for Resource has been streamlined to flask_restx, and the initialization process in the PgsqlResource class has been extended with additional *args and **kwargs. This adjustment refines how our resources are initialized, and makes handling database connections in the kwargs argument more straightforward.
Flask_restful library is replaced with flask_restx in app.py file to leverage extended functionalities provided by flask_restx. This change aims to refine the resource initialization and streamline the handling of database connections.
The required Python package flask-restx has been added to the requirements file. Migrating from the flask_restful library to flask_restx, offers added features and a smoother experience with handling database connections and initializing resources.
@maxachis maxachis changed the title Mc replace with abort Move from flask_restful to flask_restx. Replace error dictionaries with abort May 25, 2024
Copy link

@joshuagraber joshuagraber left a comment

Choose a reason for hiding this comment

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

Looks good, just one question on how this changes the error response objects.

@@ -80,25 +82,27 @@ def decorator(*args, **kwargs):
if len(authorization_header) >= 2 and authorization_header[0] == "Bearer":
api_key = request.headers["Authorization"].split(" ")[1]
if api_key == "undefined":
return {"message": "Please provide an API key"}, 400
abort(code=400, message="Please provide an API key")

Choose a reason for hiding this comment

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

@maxachis Is this going to change the shape of the error objects we receive on the client?

Copy link
Author

@maxachis maxachis Jun 12, 2024

Choose a reason for hiding this comment

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

@joshuagraber Based on my tests, yes, but only somewhat, and seemingly not in a way that should interfere. The response.json will now include a "http_status_code" key-value pair in addition to the "message" key-value pair.

So {'message': 'An unexpected error occurred'} will become {'http_status_code': 500, 'message': 'An unexpected error occurred'}

Choose a reason for hiding this comment

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

No problem @maxachis thank you.

maxachis added 4 commits June 12, 2024 16:19
# Conflicts:
#	middleware/security.py
#	resources/PsycopgResource.py
#	resources/QuickSearch.py
#	resources/RefreshSession.py
…e_with_abort

# Conflicts:
#	resources/QuickSearch.py
@maxachis maxachis merged commit 2fae1ef into dev Jun 17, 2024
8 of 10 checks passed
@maxachis maxachis deleted the mc_replace_with_abort branch June 17, 2024 11:46
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