Skip to content

Httpx and Pydantic V2 fixes #29

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

martincpt
Copy link

First of all, thank you for this fantastic package. 🙌

I really like the use of generators and yield statements. I found it extremely innovative, but unfortunately, it didn't work straightaway on my end. So, here I am, excited to contribute and send this fix.

I’m also glad this project builds on top of uvicorn, and comes with OpenAPI documentation—huge pluses all around!

What's included in this PR:

1. Fix for broken generators with the latest httpx client

Closes #27

This addresses an issue where generators using yield broke due to changes in httpx >= 0.24. Specifically, aiter_lines no longer includes line breaks and instead yields empty strings. This case has to be handled in the same logic that previously managed line breaks.

2. Fix for OpenAPI docs generation when using root return types with Pydantic v2

Closes #28

Partial support for pydantic v2 is added by detecting the installed version and using the appropriate method for model creation in OpenAPI docs. Since __root__ is no longer available in pydantic.create_model for v2, the code now uses pydantic.RootModel when needed.

3. Test fine-tuning

I removed unnecessary sleep calls from the generator tests. They added significant overhead to the test runtime—tests now complete in under a second. Ideally, tests should avoid sleep altogether (or mock time-based behavior) to keep the feedback loop fast during development.

Thanks again for this fantastic package! 🙏

I hope you agree with the changes and find them useful. Looking forward to your feedback and, hopefully, to getting this merged soon!

@abersheeran
Copy link
Owner

I'm glad you like this library. As long as you can fix the CI and get the unit tests to pass correctly, I will merge this PR soon.

@martincpt
Copy link
Author

I've checked just to be certain. The unit tests are passing correctly.

I believe there's something wrong with the CI. Could you please take a look at it?

Set up Python 3.7

Run actions/setup-python@v2
Version 3.7 was not found in the local cache
Error: The operation was canceled.

Also, I don't have any permission to rerun the CI. Maybe it was a temporary issue. Could you please try to rerun it?

@abersheeran
Copy link
Owner

It seems that GitHub has dropped support for 3.7. Based on the current popular Python versions, we can drop unit tests for 3.7 and 3.8.

@martincpt
Copy link
Author

@abersheeran, I dropped support for 3.7, 3.8 and added 3.11, 3.12 to the ci.yaml

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.

OpenAPI docs generation fails for root return types with Pydantic v2 Yield is broken using generators
2 participants