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
We are using a script to freeze copies of our staging and prod MySQL database. For development we are using SQLite, using the thawed data from MySQL. However, this issue can be replicated just from freezing and thawing between SQLite entities.
# Output from > python test.py
Original Entity
=====================
Last Login: 2018-03-13 12:06:29.403321
Type of: <class 'datetime.datetime'>
Thawed Entity
=====================
Last Login: 2018-03-13T12:06:29.403321
Type of: <class 'str'>
I noticed that freeze uses datetime.isoformat() to convert DateTimeField, and DateField - but this format is not in the format lists.
We have tested a quick fix by adding DateTimeField.formats.append('%Y-%m-%dT%H:%M:%S'), and DateField.formats.append(''%Y-%m-%dT%H:%M:%S'') to our models file - which resolved the MySQL to SqlLite issue.
From our testing between SQLite to SQLite, it would seem '%Y-%m-%dT%H:%M:%S.%f' would also need to be added to the list.
Have not tested TimeField, and I haven't been able to dig around the code enough to understand if appending it to sqlite_datetime_formats, and sqlite_date_trunc is necessary.
The text was updated successfully, but these errors were encountered:
This is a bit tricky because JSON should utilize ISO format, but Peewee really only has date-parsing logic to work-around the fact that SQLite doesn't have a native datetime data-type. By convention, Peewee has used the equivalent of Python's __str__() for datetime/date/time objects when persisting in SQLite.
Adding more formats is certainly one route, but my preference is to just change the export format to match what peewee already can handle. Fewer changes. If you want ISO, you can always subclass and extend DataSet.
Thanks @coleifer makes much more sense. Didn't occur to me to fix it at the root, thought ISO made sense as it's also what I normally use. Cheers, much appreciated.
Well that was the problem, it does make sense. But it seemed expedient to move to a serialization format that could inter-operate with Peewee as-is and leave implementing an ISO date format for a separate Exporter class.
We are using a script to freeze copies of our staging and prod MySQL database. For development we are using SQLite, using the thawed data from MySQL. However, this issue can be replicated just from freezing and thawing between SQLite entities.
Test script below to show the issue.
Which outputs the following when run.
I noticed that freeze uses datetime.isoformat() to convert DateTimeField, and DateField - but this format is not in the format lists.
We have tested a quick fix by adding
DateTimeField.formats.append('%Y-%m-%dT%H:%M:%S')
, andDateField.formats.append(''%Y-%m-%dT%H:%M:%S'')
to our models file - which resolved the MySQL to SqlLite issue.From our testing between SQLite to SQLite, it would seem
'%Y-%m-%dT%H:%M:%S.%f'
would also need to be added to the list.It would be great to have it added to the format lists at https://github.com/coleifer/peewee/blob/master/peewee.py#L3955 and https://github.com/coleifer/peewee/blob/master/peewee.py#L3974
Have not tested TimeField, and I haven't been able to dig around the code enough to understand if appending it to sqlite_datetime_formats, and sqlite_date_trunc is necessary.
The text was updated successfully, but these errors were encountered: