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

Werkzeug validate_request: 'request' argument is not type of Request #806

Open
htmhmeer opened this issue Mar 8, 2024 · 4 comments
Open
Labels
kind/bug Indicates an issue

Comments

@htmhmeer
Copy link

htmhmeer commented Mar 8, 2024

Actual Behavior

openapi_request = WerkzeugOpenAPIRequest(request)
type of openapi_request: openapi_core.contrib.werkzeug.requests.WerkzeugOpenAPIRequest

openapi.validate_request(openapi_request)

│ File "/home/odoo/.local/lib/python3.8/site-packages/openapi_core/app.py", line 347, in validate_request
│ self.validate_apicall_request(request)
│ File "/home/odoo/.local/lib/python3.8/site-packages/openapi_core/app.py", line 359, in validate_apicall_request
│ raise TypeError("'request' argument is not type of Request")

Expected Behavior

that it works like documentated here:
https://openapi-core.readthedocs.io/en/latest/integrations/werkzeug.html

Steps to Reproduce

see above

OpenAPI Core Version

Version: 0.19.0

OpenAPI Core Integration

Werkzeug

Affected Area(s)

No response

References

No response

Anything else we need to know?

am I missing something?

Would you like to implement a fix?

None

@htmhmeer htmhmeer added the kind/bug Indicates an issue label Mar 8, 2024
@p1c2u
Copy link
Collaborator

p1c2u commented Mar 10, 2024

Hi @htmhmeer

can you provide working example. Your code doesn't show what type of request object did you use.

@htmhmeer
Copy link
Author

htmhmeer commented Mar 10, 2024

from werkzeug.wrappers import Request
 
environ = request.httprequest._HTTPRequest__wrapped.environ
openapi_request = WerkzeugOpenAPIRequest(Request(environ))

openapi_request = WerkzeugOpenAPIRequest(request.httprequest._HTTPRequest__wrapped)
result = openapi.unmarshal_request(openapi_request)

The problem is that the system (Odoo) has a wrapper around the original werkzeug request so I tried making a new one with the original environ variable or using the original wrapped one, both methods give the same error when validating or unamrshalling, the WerkzeugOpenAPIRequest does work fine though.

The thing is though, I think unmarshal would work perfectly fine if that openapi-core check wouldn't be there.

@htmhmeer
Copy link
Author

If I do
isinstance(Request(environ), Request)
it returns True, however, it still gives me the same error: TypeError: 'request' argument is not type of Request
Tried:
result = openapi.unmarshal_request(Request(environ))
Same error:
I'm literally putting in the exact same Type and it just doesn't work

@p1c2u
Copy link
Collaborator

p1c2u commented Mar 10, 2024

The problem is that the system (Odoo) has a wrapper around the original werkzeug request

Because it's made for werkzeug request You can try to extract original request from it.

Alternatively Nnthing stopping you from creating your own class for the wrapper based on WerkzeugOpenAPIRequest just override __init__ method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Indicates an issue
Projects
None yet
Development

No branches or pull requests

2 participants