You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In JsonModel, find not working with class that has Optional and no default value, whereas HashModel is working
Check out below code:
classCustomerHash1(HashModel):
name: str=Field(index=True)
bio: Optional[str]
classCustomerHash2(HashModel):
name: str=Field(index=True)
bio: Optional[str] =Field(title="bio")
classCustomerHash3(HashModel):
name: str=Field(index=True)
bio: Optional[str] =Field(title="bio", default="")
classCustomerJson1(JsonModel):
name: str=Field(index=True)
bio: Optional[str]
# Not WorkingclassCustomerJson2(JsonModel):
name: str=Field(index=True)
bio: Optional[str] =Field(title="bio")
classCustomerJson3(JsonModel):
name: str=Field(index=True)
bio: Optional[str] =Field(title="bio", default="")
Migrator().run()
# HashCustomerHash1(name="Brookins").save()
print(
"HashModel with Optional and field: ",
CustomerHash1.find(CustomerHash1.name=="Brookins").all(),
)
CustomerHash2(name="Brookins").save()
print(
"HashModel with Optional and no default: ",
CustomerHash2.find(CustomerHash2.name=="Brookins").all(),
)
CustomerHash3(name="Brookins").save()
print(
"HashModel with Optional and default: ",
CustomerHash3.find(CustomerHash3.name=="Brookins").all(),
)
# JsonCustomerJson1(name="Brookins").save()
print(
"JsonModel with Optional and field: ",
CustomerJson1.find(CustomerJson1.name=="Brookins").all(),
)
# Not WorkingCustomerJson2(name="Brookins").save()
print(
"JsonModel with Optional and no default: ",
CustomerJson2.find(CustomerJson2.name=="Brookins").all(),
)
CustomerJson3(name="Brookins").save()
print(
"JsonModel with Optional and default: ",
CustomerJson3.find(CustomerJson3.name=="Brookins").all(),
)
Results:
HashModel with Optional and field: [CustomerHash1(pk='01FR9YSQ61BKYERVVCZRYED6NG', name='Brookins', bio='')]
HashModel with Optional and no default: [CustomerHash2(pk='01FR9YSQ64EXHRSA82HS9G9ZW6', name='Brookins', bio='')]
HashModel with Optional and default: [CustomerHash3(pk='01FR9YSQ66FCNFB1GC55JR4NPZ', name='Brookins', bio='')]
JsonModel with Optional and field: [CustomerJson1(pk='01FR9YSQ698MJTYY06KCTB3CQC', name='Brookins', bio=None)]
JsonModel with Optional and no default: []
JsonModel with Optional and default: [CustomerJson3(pk='01FR9YSQ6DXZZBY1BVMZWN59GC', name='Brookins', bio='')]
The text was updated successfully, but these errors were encountered:
gam-phon
changed the title
find not working with Optional and no default
JsonModel find not working with Optional and no default
Jan 1, 2022
gam-phon
changed the title
JsonModel find not working with Optional and no default
JsonModel: find not working with Optional and no default
Jan 1, 2022
HashModel with Optional and field: [CustomerHash1(pk='01GBN3QJMXME8WMG9C3MVXPT53', name='Brookins', bio='')]
HashModel with Optional and no default: [CustomerHash2(pk='01GBN3QJN1VPGRCZZ1WHPC71C2', name='Brookins', bio='')]
HashModel with Optional and default: [CustomerHash3(pk='01GBN3QJN3F3HCQ69N4R5EYKEB', name='Brookins', bio='')]
JsonModel with Optional and field: [CustomerJson1(pk='01GBN3QJN5H7G8WAQ4J471CMWV', name='Brookins', bio=None)]
JsonModel with Optional and no default: [CustomerJson2(pk='01GBN3QJN9YKYYC2KD5DB3P62J', name='Brookins', bio=None)]
JsonModel with Optional and default: [CustomerJson3(pk='01GBN3QJNB72WAAQXZN95W6SPS', name='Brookins', bio='')]
Hello,
In JsonModel, find not working with class that has Optional and no default value, whereas HashModel is working
Check out below code:
Results:
The text was updated successfully, but these errors were encountered: