django-markupfield icon indicating copy to clipboard operation
django-markupfield copied to clipboard

Incrementing `creation_counter` breaks field equality

Open mkjpryor-stfc opened this issue 4 years ago • 0 comments

These lines cannot be used to preserve ordering in forms, because Django's Field.__eq__ uses the creation_counter for equality:

markup_type_field.creation_counter = self.creation_counter + 1
rendered_field.creation_counter = self.creation_counter + 2

Unless the MarkupField is the last field in a model class, this causes a collision of creation_counter with the fields that come after. This breaks the Field equality check and hence any code that relies on field equality. For instance, I came across this bug when using django-concurrency, which relies on field equality to detect the version field.

mkjpryor-stfc avatar Oct 12 '20 15:10 mkjpryor-stfc