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 FALLBACK_ERROR_FORMAT for handlers that return empty() #2659

Merged
merged 6 commits into from
Feb 5, 2023

Conversation

Tronic
Copy link
Member

@Tronic Tronic commented Jan 19, 2023

Remove mapping of empty() to HTML, such that the fallback format will rather be used. Also removes mapping of file, redirect and other untyped responses.

This has effects on two separate cases:

  1. Routes using only the removed types will no longer automatically get any error format
  2. Routes using known types (text, json, or html) will now receive corresponding error formats when used with removed types that were conflicting, e.g. json(data) if data else empty() will receive json error format.

When there is no format from route, due to nothing found or a conflict of formats, Sanic falls back FALLBACK_ERROR_FORMAT and other methods. Note that #2668 affects how that is done but does not fix the issue below.

Users affected by this (either now or after merged) are advised to either add accept: application/json or similar header to their request or to define error_format="json" (text, html) on their routes, to get a specific format.

Fix #2658

@Tronic Tronic requested a review from a team as a code owner January 19, 2023 00:25
@codecov
Copy link

codecov bot commented Jan 19, 2023

Codecov Report

Base: 88.583% // Head: 88.642% // Increases project coverage by +0.058% 🎉

Coverage data is based on head (89f2d47) compared to base (9cb9e88).
Patch has no changes to coverable lines.

Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2659       +/-   ##
=============================================
+ Coverage   88.583%   88.642%   +0.058%     
=============================================
  Files           87        87               
  Lines         6850      6850               
  Branches      1171      1171               
=============================================
+ Hits          6068      6072        +4     
+ Misses         540       538        -2     
+ Partials       242       240        -2     
Impacted Files Coverage Δ
sanic/errorpages.py 97.938% <ø> (ø)
sanic/server/websockets/impl.py 38.479% <0.000%> (+0.921%) ⬆️

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Tronic added a commit that referenced this pull request Jan 29, 2023
@Tronic
Copy link
Member Author

Tronic commented Jan 31, 2023

This passed all tests, which means that we definitely need more tests. Will do on another PR, please merge this if OK!

@Tronic
Copy link
Member Author

Tronic commented Feb 1, 2023

Linter check is failing on some unchanged files, cannot reproduce locally, all formatted OK here.

@ahopkins ahopkins merged commit c7a71cd into main Feb 5, 2023
@ahopkins ahopkins deleted the empty-errorpage-fallback branch February 5, 2023 13:29
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.

FALLBACK_ERROR_FORMAT does not work with empty()
2 participants