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

Fix checking parameter type #110

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

hluk
Copy link
Member

@hluk hluk commented Nov 1, 2023

Workaround for a bug in flask-pydantic.

Avoids the following exception causing server to respond with HTTP 500:

Traceback (most recent call last):
File "/venv/lib64/python3.11/site-packages/flask_pydantic/core.py", line 197, in wrapper
    b = body_model(**body_params)
        ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: resultsdb.parsers.api_v3.BrewResultParams() argument after ** must be a mapping, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/venv/lib64/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib64/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib64/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
        ^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib64/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib64/python3.11/site-packages/flask_pyoidc/flask_pyoidc.py", line 463, in wrapper
    return view_func(*args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/lib64/python3.11/site-packages/flask_pydantic/core.py", line 204, in wrapper
    raise JsonBodyParsingError()
flask_pydantic.exceptions.JsonBodyParsingError

Server will respond instead with HTTP 400 and the following JSON body:

{
    "validation_error": {
        "body_params": [{
            "loc": ["__root__"],
            "msg": "value is not a valid dict",
            "type": "type_error.dict"
        }]
    }
}

JIRA: RHELWF-10108

Workaround for a bug in flask-pydantic.

Avoids the following exception causing server to respond with HTTP 500:

    Traceback (most recent call last):
    File "/venv/lib64/python3.11/site-packages/flask_pydantic/core.py", line 197, in wrapper
        b = body_model(**body_params)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: resultsdb.parsers.api_v3.BrewResultParams() argument after ** must be a mapping, not str

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/venv/lib64/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
        response = self.full_dispatch_request()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/venv/lib64/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
        rv = self.handle_user_exception(e)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/venv/lib64/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
        rv = self.dispatch_request()
            ^^^^^^^^^^^^^^^^^^^^^^^
    File "/venv/lib64/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
        return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/venv/lib64/python3.11/site-packages/flask_pyoidc/flask_pyoidc.py", line 463, in wrapper
        return view_func(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/venv/lib64/python3.11/site-packages/flask_pydantic/core.py", line 204, in wrapper
        raise JsonBodyParsingError()
    flask_pydantic.exceptions.JsonBodyParsingError

Server will respond instead with HTTP 400 and the following JSON body:

    {
        "validation_error": {
            "body_params": [{
                "loc": ["__root__"],
                "msg": "value is not a valid dict",
                "type": "type_error.dict"
            }]
        }
    }

JIRA: RHELWF-10108
@mvalik
Copy link
Contributor

mvalik commented Nov 1, 2023

Have you submit a bug report to flask_pydantic?

@hluk
Copy link
Member Author

hluk commented Nov 2, 2023

Have you submit a bug report to flask_pydantic?

No, I'm rather waiting for the update to support Pydantic 2 but it takes a long time so I'm afraid that flask-pydantic is unmaintained now.

Migrating to fastapi would solve other problems too, but it could be a lot of work (I did that for product-listings-manager).

@hluk hluk requested a review from mvalik November 6, 2023 10:14
@mvalik
Copy link
Contributor

mvalik commented Nov 8, 2023

+1

@hluk hluk merged commit b3c09aa into release-engineering:develop Nov 9, 2023
6 checks passed
@hluk hluk deleted the fix-param-type-check branch January 3, 2024 09:39
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.

None yet

2 participants