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

[Bug]: Chunked request from request libraly #554

Open
jitka opened this issue Apr 11, 2023 · 3 comments · May be fixed by #556
Open

[Bug]: Chunked request from request libraly #554

jitka opened this issue Apr 11, 2023 · 3 comments · May be fixed by #556
Labels

Comments

@jitka
Copy link
Contributor

jitka commented Apr 11, 2023

Actual Behavior

When it shout check response where request data was chunked it fails.

    @property
    def body(self) -> Optional[str]:
        if self.request.body is None:
            return None
        if isinstance(self.request.body, bytes):
            return self.request.body.decode("utf-8")
>       assert isinstance(self.request.body, str)
E       AssertionError

Expected Behavior

Check everithing which can, ideally chunked body itself.

Steps to Reproduce

    @staticmethod
    def chunk_generator(data):
        for block in raw:
            yield block
request = Request(method, url, headers=headers, data=chunk_generator(data), **kwargs)
response = session.send(session.prepare_request(request))  
openapi_request = RequestsOpenAPIRequest(request)
openapi_response = RequestsOpenAPIResponse(response)
unmarshal_response(openapi_request, openapi_response, self.spec)

OpenAPI Core Version

0.17.1

OpenAPI Core Integration

requests

Affected Area(s)

unmarshaling

References

No response

Anything else we need to know?

No response

Would you like to implement a fix?

None

@jitka jitka added the kind/bug Indicates an issue label Apr 11, 2023
@jitka
Copy link
Contributor Author

jitka commented Apr 11, 2023

possible fix

import types
class RequestsOpenAPIRequestFix(RequestsOpenAPIRequest):
    ...

    @property
    def body(self) -> Optional[str]:
        if self.request.body is None or isinstance(self.request.body, types.GeneratorType):
            return None
        if isinstance(self.request.body, bytes):
            return self.request.body.decode("utf-8")
        assert isinstance(self.request.body, str)
        # TODO: figure out if request._body_position is relevant
        return self.request.body

@p1c2u
Copy link
Collaborator

p1c2u commented Apr 13, 2023

Generator should be resolved to string and passed further to the request if we want to validate the body.

@p1c2u p1c2u linked a pull request Apr 13, 2023 that will close this issue
@p1c2u
Copy link
Collaborator

p1c2u commented Apr 13, 2023

It can be done with Request object but if user has Request object and pass only PreparedRequest to request factory we will not be able to recreate generator and the original generator will be expired in the Request object.

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

Successfully merging a pull request may close this issue.

2 participants