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

Use json rather than flask.json to generate ETag #393

Merged
merged 1 commit into from
Aug 16, 2022
Merged

Conversation

lafrech
Copy link
Member

@lafrech lafrech commented Aug 16, 2022

Historically, we used flask.json because it serializes lazy strings but this should not be the responsibility of this framework.

Then, we decided not to force sort_keys for consistency with the way flask dumps the payload (#305). But there is no reason to do that for the "explicit ETag" (arbitrary data) case. And even if the app doesn't sort keys, doing it for ETag computation makes sense.

It is not easy to provide a one-size-fits-all solution. User is free to override _generate_etag for specific cases (specific json serializer, sort_keys=False,...).

Things can probably be improved in a wider ETag rework. Meanwhile, this change simplifies the code and fixes compatibility with Flask 2.2+ without breaking compatibility with Flask <2.2.

@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Merging #393 (a136e30) into master (d508476) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #393   +/-   ##
=======================================
  Coverage   99.87%   99.87%           
=======================================
  Files          13       13           
  Lines         816      817    +1     
  Branches      178      178           
=======================================
+ Hits          815      816    +1     
  Partials        1        1           
Impacted Files Coverage Δ
flask_smorest/etag.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.

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

1 participant