Opened 5 years ago

Closed 4 years ago

#16317 closed Bug (fixed)

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

Reported by: DrMeers 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 aldaran 5 years ago.
patch and tests
16317_get_by_natural_key.patch (4.5 KB) - added by aldaran 4 years ago.
At revision 17766

Download all attachments as: .zip

Change History (13)

comment:1 Changed 5 years ago by DrMeers

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

(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 5 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

Changed 5 years ago by aldaran

patch and tests

comment:3 Changed 5 years ago by aldaran

  • 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 5 years ago by aldaran

  • Cc s.federici@… added

comment:5 Changed 4 years ago by anonymous

the patch is ready for current trunk 1.4 alpha

comment:6 Changed 4 years ago by aldaran

  • Triage Stage changed from Accepted to Ready for checkin

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

comment:7 Changed 4 years ago by akaariai

  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

The updated patch seems to be missing the part.

Changed 4 years ago by aldaran

At revision 17766

comment:8 Changed 4 years ago by aldaran

  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:9 follow-up: Changed 4 years ago by aldaran

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 4 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 4 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

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