-
Notifications
You must be signed in to change notification settings - Fork 15
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
Place.address gets added as Text type #5
Comments
Thanks for reporting this bug @thebuchanan3 . On which python version are you? |
3.10.4 |
this can probably be fixed by using the smart_union config to avoid type coercion to the first Union type: without from pydantic import BaseModel
class A(BaseModel):
item: str
class B(BaseModel):
item: str
class C(BaseModel):
item: A | B
print(C(item=B(item="a")))
# item=A(item='a') with from pydantic import BaseModel
class A(BaseModel):
item: str
class B(BaseModel):
item: str
class C(BaseModel, smart_union=True):
item: A | B
print(C(item=B(item="a")))
# item=B(item='a') |
as a workaround the setting can be set globally by patching >>> from pydantic_schemaorg.SchemaOrgBase import SchemaOrgBase
>>> SchemaOrgBase.Config.smart_union = True
>>> from pydantic_schemaorg.Place import Place
>>> from pydantic_schemaorg.PostalAddress import PostalAddress
>>> address = PostalAddress(postalCode="12345")
>>> Place(address=address).address
PostalAddress(reverse_=None, id_=None, context_=None, graph_=None, type_='PostalAddress', mainEntityOfPage=None, additionalType=None, url=None, alternateName=None, sameAs=None, name=None, identifier=None, potentialAction=None, subjectOf=None, description=None, disambiguatingDescription=None, image=None, areaServed=None, contactType=None, availableLanguage=None, serviceArea=None, email=None, hoursAvailable=None, telephone=None, contactOption=None, faxNumber=None, productSupported=None, postalCode='12345', streetAddress=None, addressLocality=None, postOfficeBoxNumber=None, addressCountry=None, addressRegion=None) |
@thebuchanan3 Great thanks :D i will patch the SchemaOrgBase to have the |
Using
pydantic_schemaorg==1.0.6
:When creating a place with an address it gets added as Text type:
When adding it after instantiation, it gets added as PostalAddress as expected:
This should probably work the same both ways.
The text was updated successfully, but these errors were encountered: