-
-
Notifications
You must be signed in to change notification settings - Fork 226
Use Optional for Query Params Instead of Union[Unset, ...] #285
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 Optional for Query Params Instead of Union[Unset, ...] #285
Comments
Oof. There's definitely not a clear answer here. The purpose of The OpenAPI spec doesn't seem to draw any distinction between location (e.g. nullable is not forbidden in query parameters). However, there is also no obvious way to send nulls in query parameters because... well they're stings. So it seems to me there is ambiguity in the spec which means it's going to be very implementation-specific how nulls are dealt with (if at all). If you pass a |
Yeah, I can totally appreciate that it's confusing to have different paths for different parameter types. I think of |
Maybe it would be useful to have a configurable
That wouldn't fix the typing problem, unless the document specified the param as nullable the generated client wouldn't accept We could also take the config a step further and if Another option is to just say that in this project |
This is probably the easiest option that solves all our problems if we're treating |
Sounds like a plan then. And if anyone ends up having different requirements around |
@bowenwr , @forest-benchling , and @emann I want to pull the discussion which has sort of spiraled out in #297 back to the issue here. In thinking about this more I want to take a different approach. I think we should not be changing type annotation based on location (query) since that's causing a lot of confusion and cascading code changes. Instead, I think we leave the function/type definitions as they are ( Instead, I think the solution here is to omit any query param with the value This is sort of a half solution to your specific problem, but I think the best way forward. The types will show incorrectly still if you pass |
Definitely seems like the cleanest solution + gives us an easy way to support |
To me, it makes it more confusing for the type annotation to not reflect the implementation. The type annotation would be saying I'm not sure the What I'm leaning towards is keeping the OpenAPI spec, the type annotations, and the implementation all in alignment, for our own sanity--AKA, the status quo. However, I do think that is a very reasonable use case to want to pass |
I think that for the sake of simplicity (and expedience, because I want to move this issue along) I'm going to go with my solution above. While the original issue here is spawned from Benchling's need to surface different types for their SDK, any solution has to be generally applicable enough to not cause undue complexity (either for consumers or within the codebase itself). That being said, the unstable custom templates feature exists for just such reasons: folks needing customization that doesn't necessarily belong in this general purpose product. You could probably achieve your original ask (replacing If there is a way we can make the custom templates feature more useful to you for this, let me know. We could, for example, potentially make the templates a separate package which you could fork and maintain as your custom templates (to make upstream changes easier to pull in). It might also make sense for all the type annotation building stuff to live in templates instead of the core Python code. Also if you think I'm missing something here and that my solution isn't the ideal one for general purpose clients, I'm always happy to reconsider. |
Is your feature request related to a problem? Please describe.
Although I'd like to keep
Unset
for body params, it makes a lot less sense for query params. I'd like non-required query params to return to the use ofOptional
.While it would be inconsistent with the way we handle body params, I like that it encapsulates
Unset
(which is something of a workaround) more tightly.Describe the solution you'd like
Given:
I'd like the signature to look like:
Instead of:
Describe alternatives you've considered
We have several endpoints with a large number of optional query params that default to
None
in the wrapping interface. Will probably just iterate the dict and assignUnset
everywhere we haveNone
now.Additional context
I feel like I did this to myself having requested the original
Unset
feature. 😅The text was updated successfully, but these errors were encountered: