etianen / django-reversion

django-reversion is an extension to the Django web framework that provides version control for model instances.
https://django-reversion.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.05k stars 489 forks source link

"Could not load - incompatible version data" for versions having an empty PartialDateField #933

Closed lefterav closed 1 year ago

lefterav commented 1 year ago

How to reproduce:

Make sure you have enabled the custom module in your Python virtual environment:

pip install django-partial-date==1.3.2 django-reversion==5.0.4

Create the following class in the django models.py:

from partial_date import PartialDateField

class Station(models.Model):
    name = models.CharField(max_length=200)
    created = PartialDateField(blank=True, null=True)

Register the administration of the object with reversion in admin.py:

from reversion.admin import VersionAdmin

@admin.register(Station)
class StationAdmin(VersionAdmin):
    pass

run migrations on your commandline:

python manage.py makemigrations
python manage.py migrate
  1. Login in the admin interface and create a Station object. Provide only a value for the "name" field and leave all the rest empty. Click save and continue editing.
  2. Provide a partial date value in the "Created" the field. E.g. "2020-05". Click save and continue editing
  3. Click on history.
  4. Click on the older version you created before: unintended behavior: "Could not load Name version - incompatible version data."
  5. Click on the latest version with the partial date specified: intended behavior. The version loads properly
etianen commented 1 year ago

If you enable logging for django-reversion, you'll get a stack trace. I'd be interested to see.

Likely this is a problem with PartialDateField and django's serialization framework. django-reversion relies on that working correctly, and doesn't really introduce any serialization logic of it's own.