Opened 8 years ago

Closed 7 years ago

#16317 closed Bug (fixed)

Self-referencing model with natural key: dumpdata can't resolve dependencies

Reported by: Simon Meers Owned by: nobody
Component: Core (Serialization) Version: 1.3
Severity: Normal Keywords:
Cc: s.federici@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a self-referencing model with a natural key, but dumpdata won't serialize it:

    Error: Can't resolve dependencies for app_label.ModelName in serialized app list

This is probably perfectly valid if use_natural_keys=True, but shouldn't I be able to serialize it without natural keys? I suspect dumpdata.sort_dependencies should take the flag setting into consideration before throwing natural-key-based dependencies into the mix?

Attachments (2)

get_by_natural_key.patch (4.5 KB) - added by Simone 8 years ago.
patch and tests
16317_get_by_natural_key.patch (4.5 KB) - added by Simone 8 years ago.
At revision 17766

Download all attachments as: .zip

Change History (13)

comment:1 Changed 8 years ago by Simon Meers

(the intention is to serialise the self-referencing model separately natural keys, but use the natural key functionality in references from other models)

comment:2 Changed 8 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

Changed 8 years ago by Simone

Attachment: get_by_natural_key.patch added

patch and tests

comment:3 Changed 8 years ago by Simone

Has patch: set

The patch is valid for ForeignKey, ManyToMany and OneToYne Fields
I've added a simple test case.

There is another problem related to this issue, in order to load "self related objects" by natural keys using get_by_natural_key()
is obvious think that the related instances are already in the database.
The Serializator needs to serialize in a intelligent order (but if there are cycle dependency it is impossible) or by serializing the objects with no relations and after another serialization with them. I don't want open another issue for that, actually I think it is possible by writing the fixtures by hand.

comment:4 Changed 8 years ago by Simone

Cc: s.federici@… added

comment:5 Changed 8 years ago by anonymous

the patch is ready for current trunk 1.4 alpha

comment:6 Changed 8 years ago by Simone

Triage Stage: AcceptedReady for checkin

I've update the patch, for the new release 17765, the content is not changed.

comment:7 Changed 8 years ago by Anssi Kääriäinen

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

The updated patch seems to be missing the part.

Changed 8 years ago by Simone

At revision 17766

comment:8 Changed 8 years ago by Simone

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 Changed 8 years ago by Simone

Yes thanks, you're right.
in the previous upload the part was missing
now I've update the patch for the new release 17766

comment:10 in reply to:  9 Changed 7 years ago by duilio

what happened to this patch? I've just caught this bug and found out it was issued here

comment:11 Changed 7 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In [4b722b31e1778310ba0c1ed96fdacf99aa203dd2]:

Fixed #16317 -- Fixed dumpdata for self-referencing models and natural keys

Thanks aldaran for the patch.

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