-
-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
please document how to deserialize by natural key #517
Comments
It looks like in this spot
there needs to be some special casing for ForwardOneToOneDescriptor, that instantiates the parent model (as long as none of the required fields are deferred), the way that Django does here:
I haven't studied this to see exactly what it would imply, though. |
@vdboor, what do you think? I wonder if you could assist me with the implications part, and what a good fix ought to look like? I've been planning to implement JSON import and export in my application's admin. That will have to use the natural keys. So, I think, I have to either fix this issue or take the library out. Perhaps if I can figure out how to correct it within django-polymorphic, I can then potentially turn that into a subclass implementation for interim use. |
As an experiment, I commented out the
It fails here, which is a test that uses an inheritance hierarchy A -> B -> C to check that if A is queried for an object that's also a C, its B instance will be of class B. With the I still don't understand. |
Tracing the original example, I realized that the definition of Correct version of the example code is:
And then (using
And then I noticed that, during the loaddata process, after the There's some stuff in the stack trace that, when I inspect that part of the Django source, appears to involve copying over of manager methods in the inheritance scenario. I'm closer, now. |
Ah! So, now that I understand what's going on in the internals: the
I'm leaving this open, because it should be mentioned in the managers section of the documentation. |
I've created a minimal recreation to verify that this works in Django normally, with model inheritance. You can have a
demo/models.py
like this:And then when you create a bar instance:
Bar(slug='baz', val=1).save()
We can dump that with
./manage.py dumpdata --natural-primary --natural-foreign demo > dump.json
and get a file that works when we runloaddata
on it.Additionally, let's say we want to copy these values, but in a new instance, so run:
sed s/baz/qux/g < dump.json > new.json
Then, running
loaddata new.json
there will be two bar instances, baz and qux. Also, two instances of the base object.But, repeating the same process, but with
Foo
changed to aPolymorphicModel
andFooManager
changed to aPolymorphicManager
, I find that the first part, reloading instances that are already in the database, works, while in the second part I get the following error:Any idea why that would occur? Thanks for looking at this.
The text was updated successfully, but these errors were encountered: