#34697: Migration serializer for sets results in indeterministic output due
unstable iteration order / hash randomization
-------------------------------------------+------------------------
Reporter: Yury V. Zaytsev | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
We are using quite a lot of complex `index_together` / `unique_together`
constraints on our models, and the output in the generated migrations is
flip-flopping all the time like follows, causing spurious diffs in our
checkouts:
{{{
migrations.AlterUniqueTogether(
+ unique_together={("tenant", "dealer"), ("tenant", "order")},
- unique_together={("tenant", "order"), ("tenant", "dealer")},
}}}
This is happening because these constraints are normalized to sets
internally in the ModelState, which kind of makes sense, but unfortunately
set iteration order (unlike dicts!) is unstable in Python 3 due to hash
randomization. However, migrations serializer doesn't have any special
facilities for ensuring stable output for sets and this is what causes
annoying diffs for us all the time.
I suggest to add a trivial serializer specifically for unordered sequences
which ensures stable output no matter the iteration order. Stability can
be achieved by sorting elements in the set by their string representation.
This only affects the writer output, and doesn't interfere with the rest
of Django in any way, so this change only improves developer experience,
but has no effect on the performance and/or reliability.
I hope that even though it's apparently not a major problem for most users
you would still accept the fix to ensure stable migration writer output
for the rest of us.
--
Ticket URL: <https://code.djangoproject.com/ticket/34697>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701892bf6e862-e5ca31ab-8101-4e11-a49a-137fd606b555-000000%40eu-central-1.amazonses.com.