-
Notifications
You must be signed in to change notification settings - Fork 211
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: allows AnyUrl
pydantic types
#2286
base: devel
Are you sure you want to change the base?
Conversation
Without this change, serializing a model with `AnyUrl` fails
✅ Deploy Preview for dlt-hub-docs canceled.
|
try: | ||
from pydantic import AnyUrl as PydanticAnyUrl | ||
except ImportError: | ||
PydanticAnyUrl = None # type: ignore[misc] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cargo-culted this from above - I am assuming this is for the case when the Pydantic classes are not available and meant to gracefully degrade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are too many different types that we could add this way. my take for this PR would be to add pluggable custom_encde_extension
that is NULL by default and that you can set in json
module if you need special types to be serialized. so you could add your special type handling you just plug in your encoder. such thing we are happy to merge. so
- at the end of cutom_encode call
custom_encde_extension
(if not None) and return wha it returns or if it returns None, raise TypeError like previously - add tests along other json tests
Also mind that maybe this is not the place you really want to plug your encoders.
between extract and normalize (where all weird types happen) we use custom_pua_encode
so 90% you want to plug your encoder there. lmk. glad to help
I think that makes sense. Do you want to give me an interface signature of your choosing with a 3 line example on how to use it and I'll implement it? |
Without this change, serializing a model with
AnyUrl
fails.A sample pydantic model would be:
The error with such an entity yielded from a resource looks like this:
Details:
Please let me know if this is an acceptable fix, then I will add a test