#8134 closed (fixed)
loaddata refuses to load intermediary model target model
Reported by: | 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)
Change History (10)
comment:1 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → 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.
follow-up: 4 comment:3 by , 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?
comment:4 by , 16 years ago
Component: | django-admin.py → 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 :-)
comment:5 by , 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 , 16 years ago
Attachment: | imtest1.tar.gz added |
---|
small app with README to reproduce actual loaddata SNAFU
comment:6 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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