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

Changed Response to use body: bytes #375

Merged
merged 9 commits into from
Feb 4, 2023

Conversation

madhavajay
Copy link
Contributor

@madhavajay madhavajay commented Jan 27, 2023

Description

  • Added ActixBytesWrapper to conform to pyclass and MessageBody

This PR fixes #374

I know that my code is not optimal, but I wanted to see what the problem was and if i could get it to work.

I don't have a lot of experience with Rust or Maturin / pyo3 and I get really confused on the lifetimes, copying of bytes etc.

Was there a different goal in mind for allowing Robyn to return bytes?
One thing that is a problem is, if the Response() struct body contains a string I can't detect it in the _format_response method because the rust struct has no getters. This means a python user can use a string in body and it will fail.

It would be good to be able to detect this, or maybe the Rust struct needs to take a Union type and detect the string and convert it then?

I look forwards to feedback on my PR! 🦀

- Added ActixBytesWrapper to conform to pyclass and MessageBody
@netlify
Copy link

netlify bot commented Jan 27, 2023

Deploy Preview for robyn canceled.

Name Link
🔨 Latest commit 1918380
🔍 Latest deploy log https://app.netlify.com/sites/robyn/deploys/63de76ad9d9b4000084943aa

@sansyrox
Copy link
Member

Thank you for the PR @madhavajay 😄 The pr looks nice from the first glance but I will do a thorough review tomorrow morning 😄

Copy link
Collaborator

@AntoineRR AntoineRR left a comment

Choose a reason for hiding this comment

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

Hi @madhavajay, and thanks for this PR!
I found a way to fix the issue you had with breaking compatibility with str return type. I left some suggestions that will make your code compatible with both bytes and str.
The ActixBytesWrapper struct is actually very useful and it could probably help with other features in the future too, good job on this!

src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
robyn/router.py Outdated Show resolved Hide resolved
@AntoineRR
Copy link
Collaborator

@sansyrox feel free to add your comments too if you have some, I focused mostly on the str vs bytes issue 😉

Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

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

Hey @madhavajay 👋

Thank you for your PR. The ActixBytesWrapper is a very helpful struct 😄 and thank you @AntoineRR for the review 😄

I have a few inline comments in addition to @AntoineRR 's review

integration_tests/base_routes.py Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
@madhavajay
Copy link
Contributor Author

@AntoineRR and @sansyrox thanks for the feedback. I have made the changes.

I thought it might be a good idea to include a bad input test but the async one doesn't await and i'm not sure how to get pytest to work with async?

@AntoineRR
Copy link
Collaborator

That's a good idea to include a test for bad input. It should however be done without the session fixture, just by creating the Response struct with an invalid body and asserting we get a ValueError Exception IMO. Doing it this way there is no need to call a route on the server.

@madhavajay
Copy link
Contributor Author

@AntoineRR I tried but it seems like the exceptions aren't catchable right now so I think ill just remove this so we can merge and then this can be addressed separately.

Screen Shot 2023-01-30 at 8 12 29 pm

Screen Shot 2023-01-30 at 8 12 10 pm

src/types.rs Outdated Show resolved Hide resolved
src/types.rs Outdated Show resolved Hide resolved
Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

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

Hey @madhavajay 👋

Thank you for the updates. 😄

I just have a few final suggestions

- Parameterized body test fixtures
Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

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

This looks good to me 😄

@AntoineRR , do you want to give it a final glance?

@AntoineRR
Copy link
Collaborator

LGTM 👍

@sansyrox
Copy link
Member

sansyrox commented Feb 4, 2023

@madhavajay , there's just one final conflict. Everything else looks good 😄

@AntoineRR
Copy link
Collaborator

The conflict was with my test refactor, I solved it from Github 🙂

@sansyrox sansyrox merged commit 4ef66b5 into sparckles:main Feb 4, 2023
@sansyrox
Copy link
Member

sansyrox commented Feb 4, 2023

Thank you @madhavajay and @AntoineRR . Great work 😄

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.

[BUG] Can't send raw bytes
3 participants