Opened 9 years ago

Closed 9 years ago

#24340 closed Bug (fixed)

Nested deconstruction does not descend into lists, tuples or dicts

Reported by: Matt Westcott Owned by: Matt Westcott
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.db.migrations.autodetector.deep_deconstruct returns list, tuple and dict values untouched, rather than recursively deconstructing the items within those collections. This causes problems when those items are objects with deconstruct methods, which compare as equal when deconstructed but not when compared directly - in these cases, the autodetector will wrongly report a change to the field.

(I'll share the details of my rather esoteric use case if you really want, but given that deep_deconstruct already includes specific handling for classes and fields as parameters of a model field, I dare say that it's not too much of a leap to include these types as well!)

Change History (10)

comment:1 by Matt Westcott, 9 years ago

Owner: changed from nobody to Matt Westcott
Status: newassigned

comment:2 by Matt Westcott, 9 years ago

Has patch: set

PR: https://github.com/django/django/pull/4129

Note that I've stopped short of supporting deconstruction of sets and dict keys, because the return value of deep_deconstruct is not hashable.

comment:3 by Markus Holtermann, 9 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:4 by Matt Westcott, 9 years ago

Needs tests: unset
Patch needs improvement: unset

comment:5 by Matt Westcott, 9 years ago

Needs tests: set
Patch needs improvement: set

comment:6 by Matt Westcott, 9 years ago

Needs tests: unset
Patch needs improvement: unset

comment:7 by Matt Westcott, 9 years ago

@MarkusH - regarding the needs_documentation flag, is that something I can usefully work on? If so, can you let me know what sort of documentation you have in mind, as this doesn't seem like a particularly user-facing part of Django...?

The nearest thing in the docs is probably https://docs.djangoproject.com/en/dev/topics/migrations/#serializing-values , and this already states that list/tuple/dict are supported (which is correct - serialization in general works, it's only the autodetector that has problems).

comment:8 by Markus Holtermann, 9 years ago

Needs documentation: unset
Version: 1.7master

Hey gasman. I'm sorry that this ticket somehow got under my radar.

The only thing that was missing when I set the flag were release notes. But I wouldn't backport it now, so it will be in 1.9. Thus the only thing that needs to be done is squashing the commits and rebasing them onto the current master and make sure all tests pass.

Thanks :)

comment:9 by Matt Westcott, 9 years ago

Thanks! Rebased / squashed now.

comment:10 by Markus Holtermann <info@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In ff8a02a:

Fixed #24340 -- Added nested deconstruction for list, tuple and dict values

Nested deconstruction should recursively deconstruct items within list,
tuple and dict values.

Note: See TracTickets for help on using tickets.
Back to Top