revision with json serialized_data fails upon DateField
See original GitHub issueHi!
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.']
Issue Analytics
- State:
- Created 12 years ago
- Comments:25 (15 by maintainers)
Top Results From Across the Web
Django Rest Framework Date field serialization problems
im trying to post the recruitment date of an employee , but i keep having the 400 bad request error and recruitment_date: ["This...
Read more >Updating a task definition using the classic console
On the task definitions page, select the box to the left of the task definition to revise and choose Create new revision. On...
Read more >Changelog Archive - Jenkins
This release build failed due to packaging changes. ... Jenkins 2.353 was not placed in the artifact repository or on the download site....
Read more >Ostrovsky Rodenski - Springer Link
When a node in the cluster fails, the Couchbase Server cluster makes one of the ... Couchbase Server can store data as JSON...
Read more >2770921-36.patch - Drupal
+ * + * This method simulates the form submission on path ... +namespace Drupal\Tests\comment\Functional; use Drupal\Component\Serialization\Json; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Thanks for your answer and this amazing library!
You are absolutely right, the best solution is fixing the root problem. However, let me make clear that the problem is caused for assigning a datetime to date field and that we haven’t detected any noticeable side effect after applying this workaround.
Thanks again!