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

✨ Update ORJSONResponse to support non str keys and serializing Numpy arrays #3892

Merged
merged 8 commits into from Sep 2, 2022

Conversation

baby5
Copy link
Contributor

@baby5 baby5 commented Sep 11, 2021

the detail see: ijl/orjson#197

my case is <class 'sqlalchemy.sql.elements.quoted_name'>

Copy link

@adam-tokarski adam-tokarski left a comment

Choose a reason for hiding this comment

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

Please provide any tests for that.

@baby5
Copy link
Contributor Author

baby5 commented Oct 6, 2021

@adam-tokarski done

@app.get("/orjson_non_str_keys")
def get_orjson_non_str_keys():
key = quoted_name("msg")
return {key: "Hello World"}

Choose a reason for hiding this comment

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

Isn't that key still a string? It seems like it should be working even before the fix (I didn't check that though).

Also, you could provide a test with some integer as a key maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it is a string, but not a str type, orjson not support without option=orjson.OPT_NON_STR_KEYS
'integer as a key' is coming

@baby5
Copy link
Contributor Author

baby5 commented Oct 6, 2021

@adam-tokarski done

@tiangolo tiangolo changed the title Update orjson support non str keys ✨ Update ORJSONResponse to support non str keys and serializing Numpy arrays Sep 2, 2022
@tiangolo
Copy link
Owner

tiangolo commented Sep 2, 2022

Great, thank you @baby5! And thanks for adding tests! 🍰

And thanks @adam-tokarski for the help and review! ☕

I updated the implementation a bit to include serializing Numpy arrays and testing the included ORJSONResponse, because those tests test a custom one that doesn't include these changes.

This will be available in the next release, in the next hours, FastAPI 0.82.0. 🎉

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2022

📝 Docs preview for commit 37621c8 at: https://6311d5f220a23774734691d2--fastapi.netlify.app

@tiangolo tiangolo enabled auto-merge (squash) September 2, 2022 10:16
@codecov
Copy link

codecov bot commented Sep 2, 2022

Codecov Report

Merging #3892 (f136624) into master (173b891) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #3892   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          537       538    +1     
  Lines        13856     13870   +14     
=========================================
+ Hits         13856     13870   +14     
Impacted Files Coverage Δ
fastapi/responses.py 100.00% <100.00%> (ø)
tests/test_orjson_response_class.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tiangolo tiangolo merged commit 7250c19 into tiangolo:master Sep 2, 2022
@NikosAlexandris
Copy link

What is the status of this issue regarding support for NumPy arrays ?

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

4 participants