Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8134 closed (fixed)

loaddata refuses to load intermediary model target model

Reported by: rockmhoward@… Owned by: killiands
Component: Core (Serialization) Version: dev
Severity: Keywords: loaddata intermediary
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I used dumpdata to dump output for a model and its' intermediary model which was defined in the same models.py file. The dumped data (which is in JSON format) looks fine.

Later I tried to use loadata to read in this JSON file, but that failed and the failure was denoted by an AttributeError telling me to use the intermediary model's manager to load the data. Well then I guess that loaddata should do that (or some other workaround put in place to allow loaddata to do its' thing.)

I don't have a trivial example at hand right now, but I will supply one if it is needed.

I am using a very recent trunk (8022) in development. I have used the intermediary model that I have created quite heavily in development mode and it works great. I discovered the problem when moving my app to my production server which is also running a very recent version of trunk.

Attachments (3)

intermediaryfixtures.diff (715 bytes ) - added by killiands 16 years ago.
Patch proposal
intermediatefixturestest.diff (3.9 KB ) - added by killiands 16 years ago.
test cases
imtest1.tar.gz (3.4 KB ) - added by rock@… 16 years ago.
small app with README to reproduce actual loaddata SNAFU

Download all attachments as: .zip

Change History (10)

comment:1 by Russell Keith-Magee, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

I can see why this would happen. m2m intermediate models can't be serialized like normal m2m fields; I'm guessing the solution is that the deserializer needs to consider the 'creates_table' attribute on the m2m field. However, we will need to resolve this before v1.0

comment:2 by killiands, 16 years ago

Owner: changed from nobody to killiands
Status: newassigned

Quickly looked in to it, in my opinion the real mistake lies with the save method of the DeserializedObject. Will commit a pacht within a moment.

by killiands, 16 years ago

Attachment: intermediaryfixtures.diff added

Patch proposal

comment:3 by killiands, 16 years ago

Has patch: set

I tested the patch on my own site that uses both intermediary and non-intermediary manyToMany fields. All fixtures worked fine.

I looked into the loaddata and deserialization as suggested for the patch but wouldn't it actually be better just not to serialize intermediary ManyToMany fields to begin with?

in reply to:  3 comment:4 by Russell Keith-Magee, 16 years ago

Component: django-admin.pySerialization

Replying to kire:

I looked into the loaddata and deserialization as suggested for the patch but wouldn't it actually be better just not to serialize intermediary ManyToMany fields to begin with?

Thinking about this some more, you're probably right. Attempting to deserialize m2m_field = [1,2,3] should be an error; I haven't checked, but I suspect that this will be what an m2m field outputs by default, regardless of whether it is an intermediate or not. m2m fields should be skipped in serialization, relying upon the serialization of the intermediate model.

Regardless of the solution, the patch needs a test case before it will be committed. Tests are not optional :-)

by killiands, 16 years ago

test cases

comment:5 by killiands, 16 years ago

Okay, since cmopletely getting m2m out of the serialization process was a little more work I decided to provide tests for my original patch first. I'm not the guy to triage here, but I suggest you apply this patch so it works and create a new ticket to recode the serialization system. Maybe I'll accept that one also, but at least there's a fix for now ;-).

by rock@…, 16 years ago

Attachment: imtest1.tar.gz added

small app with README to reproduce actual loaddata SNAFU

comment:6 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [8321]) Fixed #8134 -- Corrected serialization of m2m fields with intermediate models. Thanks to Rock Howard for the report, and kire for the test case.

comment:7 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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