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
The CloudEvent model, like Pydantic's BaseModel, can serialize of datetime properties to strings in the .json() function.
Actual Behavior
The CloudEvent model raises a ValueError from the standard library's json.dumps function when .json() is called on a model containing datetime properties in the data field.
Alternatively, if this is intentional behavior, it would be helpful to have some guidance around what the expected usage is when users want to have dates or timestamps in their CloudEvent data.
Steps to Reproduce the Problem
Init a CloudEvent where some element of the data argument is a datetime instance.
By contrast, Pydantic's BaseModel is able to encode datetime properties:
fromdatetimeimportdatetimefrompydanticimportBaseModelclassMyModel(BaseModel):
dt: datetimefoo=MyModel(dt=datetime.now())
# encodes dt as a stringprint(foo.json())
Specifications
Platform: MacOS Ventura 13.2.1 (Intel)
Python Version: 3.9.9
The text was updated successfully, but these errors were encountered:
Thx for opening the issue. And yes, currently JSON behavior is not configurable. The Pydantic model is able to perform the conversion while it uses a separate JSON serialization approach.
This should be improved all over the SDK as I mentioned here.
Expected Behavior
The CloudEvent model, like Pydantic's BaseModel, can serialize of
datetime
properties to strings in the.json()
function.Actual Behavior
The CloudEvent model raises a
ValueError
from the standard library'sjson.dumps
function when.json()
is called on a model containingdatetime
properties in thedata
field.Alternatively, if this is intentional behavior, it would be helpful to have some guidance around what the expected usage is when users want to have dates or timestamps in their CloudEvent data.
Steps to Reproduce the Problem
data
argument is adatetime
instance..json()
on the CloudEvent instanceFor example:
By contrast, Pydantic's BaseModel is able to encode datetime properties:
Specifications
The text was updated successfully, but these errors were encountered: