Code

Opened 3 years ago

Closed 22 months 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

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

Download all attachments as: .zip

Change History (13)

comment:1 Changed 3 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 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

Changed 2 years ago by aldaran

patch and tests

comment:3 Changed 2 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 2 years ago by aldaran

  • Cc s.federici@… added

comment:5 Changed 2 years ago by anonymous

the patch is ready for current trunk 1.4 alpha

comment:6 Changed 2 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 2 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 dumpdata.py part.

Changed 2 years ago by aldaran

At revision 17766

comment:8 Changed 2 years ago by aldaran

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

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

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

comment:10 in reply to: ↑ 9 Changed 2 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 22 months 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.