Django

Code

Ticket #8134 (closed: fixed)

Opened 4 months ago

Last modified 4 months ago

loaddata refuses to load intermediary model target model

Reported by: rockmhoward@gmail.com Assigned to: kire
Milestone: 1.0 Component: Serialization
Version: SVN Keywords: loaddata intermediary
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

intermediaryfixtures.diff (0.7 kB) - added by kire on 08/09/08 09:17:54.
Patch proposal
intermediatefixturestest.diff (3.9 kB) - added by kire on 08/09/08 12:38:33.
test cases
imtest1.tar.gz (3.4 kB) - added by rock@rockmhoward@gmail.com on 08/09/08 17:28:55.
small app with README to reproduce actual loaddata SNAFU

Change History

08/07/08 07:28:52 changed by russellm

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • milestone set to 1.0.

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

08/09/08 09:17:29 changed by kire

  • owner changed from nobody to kire.
  • status changed from new to assigned.

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.

08/09/08 09:17:54 changed by kire

  • attachment intermediaryfixtures.diff added.

Patch proposal

(follow-up: ↓ 4 ) 08/09/08 09:25:04 changed by kire

  • has_patch set to 1.

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 ) 08/09/08 09:33:45 changed by russellm

  • component changed from django-admin.py to Serialization.

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 :-)

08/09/08 12:38:33 changed by kire

  • attachment intermediatefixturestest.diff added.

test cases

08/09/08 12:43:46 changed by kire

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 ;-).

08/09/08 17:28:55 changed by rock@rockmhoward@gmail.com

  • attachment imtest1.tar.gz added.

small app with README to reproduce actual loaddata SNAFU

08/15/08 07:26:17 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

(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.


Add/Change #8134 (loaddata refuses to load intermediary model target model)




Change Properties
Action