Brian Newman
10/02/2023, 9:34 PMclass User(BaseModel):
"""Pydantic model for the User."""
email: Optional[str]
firstName: Optional[str]
lastName: Optional[str]
@task()
def user_json(user: User):
"""Should return a JSON representation of only the set fields in the User model."""
print(user)
# Outputs: email=None firstName='John' lastName=None
print(user.json(exclude_unset=True))
# Outputs: {"email": null, "firstName": "John", "lastName": null}
return user.json(exclude_unset=True)
@flow()
def fl_create_user():
"""Creates a new user with only the first_name set and calls the user_json task."""
user = User(firstName="John")
print(user)
# Outputs: email=None firstName='John' lastName=None
print(user.json(exclude_unset=True))
# Outputs: {"firstName": "John"}
json_user = user_json(user)
print(json_user)
# Outputs: {"email": null, "firstName": "John", "lastName": null}
Alexander Azzam
10/02/2023, 9:46 PMAlexander Azzam
10/02/2023, 9:47 PMUriel Mandujano
10/02/2023, 11:07 PMNone
s and then construct it again (explicitly setting the None
we found during deconstruction). As you found, one of the pieces of info we lose during re-construction is the fields that were unset.
I have a fix in the works that'll keep track of which fields were unset during reconstruction.Uriel Mandujano
10/03/2023, 2:44 AM