django-reversion: revision with json serialized_data fails upon DateField
Hi!
my reversioned model contains a DateField called “date”. Django-reversion used to, and still does, work fine with that model if the serialized_data is xml. With json serialized_data it fails: see exception added below, reproduced in manage.py shell.
I narrowed down the problem to wrong json data: django-reverison produces a revision whith json serialized_data which contains “date”: “2011-05-05 00:00:00”. So if i change that to “date”: “2011-05-05” everything’s back to normal.
/path/to/latest/reversion/models.pyc in get_object_version(self)
187 if isinstance(data, unicode):
188 data = data.encode("utf8")
--> 189 return list(serializers.deserialize(self.format, data))[0]
190
191 object_version = property(get_object_version,
/usr/lib/pymodules/python2.7/django/core/serializers/json.pyc in Deserializer(stream_or_string, **options)
33 else:
34 stream = stream_or_string
---> 35 for obj in PythonDeserializer(simplejson.load(stream), **options):
36 yield obj
37
/usr/lib/pymodules/python2.7/django/core/serializers/python.pyc in Deserializer(object_list, **options)
126 # Handle all other fields
127 else:
--> 128 data[field.name] = field.to_python(field_value)
129
130 yield base.DeserializedObject(Model(**data), m2m_data)
/usr/lib/pymodules/python2.7/django/db/models/fields/__init__.pyc in to_python(self, value)
609
610 if not ansi_date_re.search(value):
--> 611 raise exceptions.ValidationError(self.error_messages['invalid'])
612 # Now that we have the date string in YYYY-MM-DD format, check to make
613 # sure it's a valid date.
ValidationError: [u'Enter a valid date in YYYY-MM-DD format.']
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 25 (15 by maintainers)
I’d still strongly suggest finding the bit of your code that’s assigning a string to a datetime field, and fixing the root problem there.
Sure, parts of Django are okay with this, but other parts are not.
On 30 July 2018 at 18:32, Jesús Avellaneda Menchón <notifications@github.com