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

fix(api): Create workaround for null union with multiple types #64834

Conversation

schew2381
Copy link
Member

See comment in code for detail

@schew2381 schew2381 self-assigned this Feb 8, 2024
@schew2381 schew2381 requested a review from a team as a code owner February 8, 2024 00:08
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 8, 2024
Copy link
Contributor

@nhsiehgit nhsiehgit left a comment

Choose a reason for hiding this comment

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

🙌 nice! Thanks for figuring this out!

@@ -146,7 +146,16 @@ def resolve_type_hint(hint) -> Any:
else:
schema = resolve_type_hint(type_args[0])
if type(None) in args:
schema["nullable"] = True
# There's an issue where if 3 types are OR'd together and one of
Copy link
Member

Choose a reason for hiding this comment

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

wanna double check, what does this function look like on drf-spectacular's main branch now? do we need this shim anymore now that we're on an up to date python version?

Copy link
Member Author

@schew2381 schew2381 Feb 8, 2024

Choose a reason for hiding this comment

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

Hmm I think we might be able to use the original now. The typeddict part looks like it'll work, the only difference is it doesn't look like it excludes fields like ours. in _resolve_typeddict?

It seems the very recent version also now supports openapi 3.1 which drops nullable in favor of null, although I don't see the code doing this in the Union check in resolve_type_hint 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually I just saw this: tfranzel/drf-spectacular#925
Someone brought up this exact null issue

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

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

requesting changes until we verify the drf-spectacular's upstream doessn't already have this fix

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

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

thanks @schew2381 for checking. if you get time, could be worth trying to contribute the "excluded_fields" change upstream, and perhaps showing what we're doing to attempt to fix in that thread.

if we can get both of those things figured out, would be lovely to be able to get rid of this shim!

Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (8ec3015) 63.45% compared to head (d3a5b66) 81.38%.

❗ Current head d3a5b66 differs from pull request most recent head 888c014. Consider uploading reports for the commit 888c014 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #64834       +/-   ##
===========================================
+ Coverage   63.45%   81.38%   +17.92%     
===========================================
  Files        5218     5241       +23     
  Lines      231033   231351      +318     
  Branches    45341    45380       +39     
===========================================
+ Hits       146608   188288    +41680     
+ Misses      78854    37212    -41642     
- Partials     5571     5851      +280     
Files Coverage Δ
src/sentry/apidocs/spectacular_ports.py 52.77% <33.33%> (-1.51%) ⬇️

... and 1671 files with indirect coverage changes

@schew2381 schew2381 force-pushed the seiji/fix/correct-schema-for-union-with-null-and-2-or-more-types branch from d3a5b66 to 888c014 Compare February 8, 2024 18:56
@schew2381 schew2381 merged commit 8fc6989 into master Feb 8, 2024
48 checks passed
@schew2381 schew2381 deleted the seiji/fix/correct-schema-for-union-with-null-and-2-or-more-types branch February 8, 2024 22:07
@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants