Opened 13 years ago

Closed 12 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

Description

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 12 years ago.
patch and tests
16317_get_by_natural_key.patch (4.5 KB ) - added by Simone 12 years ago.
At revision 17766

Download all attachments as: .zip

Change History (13)

comment:1 by Simon Meers, 13 years ago

(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 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

by Simone, 12 years ago

Attachment: get_by_natural_key.patch added

patch and tests

comment:3 by Simone, 12 years ago

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 by Simone, 12 years ago

Cc: s.federici@… added

comment:5 by anonymous, 12 years ago

the patch is ready for current trunk 1.4 alpha

comment:6 by Simone, 12 years ago

Triage Stage: AcceptedReady for checkin

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

comment:7 by Anssi Kääriäinen, 12 years ago

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

The updated patch seems to be missing the dumpdata.py part.

by Simone, 12 years ago

At revision 17766

comment:8 by Simone, 12 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 by Simone, 12 years ago

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

in reply to:  9 comment:10 by duilio, 12 years ago

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

comment:11 by Claude Paroz <claude@…>, 12 years ago

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