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
>>> a = Asdf()
>>> a.t
datetime.datetime(2021, 7, 12, 9, 26, 27, 251799)
# Wait several seconds, then
>>> b = Asdf()
>>> b.t
datetime.datetime(2021, 7, 12, 9, 26, 27, 251799)
Note that the timestamps are identical, even though I waited several seconds between the two. This is because the default value is evaluated upon class creation, and doesn't change after that. The proper solution (for dataclasses, at least), would use field() to define the column, like so:
Describe the bug
Using
now()
as the default value of a timestamp column in the DDL results in a hard-coded default timestamp.To Reproduce
Run the following:
The output is
Using the returned code, run the following:
Note that the timestamps are identical, even though I waited several seconds between the two. This is because the default value is evaluated upon class creation, and doesn't change after that. The proper solution (for dataclasses, at least), would use
field()
to define the column, like so:This will result in the correct behavior, where the timestamp changes for every instantiation.
Expected behavior
The default value should be the time when the instance of the class was created, not when the module defining its class was first imported.
Additional context
Python: 3.8.2
Version: 0.8.1
The text was updated successfully, but these errors were encountered: