Hello!
I have these classes:
class SuperClassManager(models.Manager):
def get_by_natural_key(self, identifier):
return self.get(identifier=identifier)
class SuperClass(models.Model):
objects = SuperClassManager()
identifier = models.CharField(max_length=31, unique=True)
def natural_key(self):
return (self.identifier, )
class SubClass(SuperClass):
pass
class SubClassTwo(SuperClass):
pass
When I do
./manage.py dumpdata --natural-foreign --natural-primary --indent 4 app
I get:
[
{
"model": "app.superclass",
"fields": {
"identifier": "one",
}
},
{
"model": "app.superclass",
"fields": {
"identifier": "two",
}
},
{
"model": "app.subclass",
"fields": {}
},
{
"model": "app.subclasstwo",
"fields": {}
}
]
The problem is: superclass of identifier one is a subclass or a subclasstwo? There's no way to tell. Shouldn't the output be
[
{
"model": "app.superclass",
"fields": {
"identifier": "one",
}
},
{
"model": "app.superclass",
"fields": {
"identifier": "two",
}
},
{
"model": "app.subclass",
"fields": {
"superclass_ptr": [
"one"
]
}
},
{
"model": "app.subclasstwo",
"fields": {
"superclass_ptr": [
"two"
]
}
}
]
Now you can tell that superclass of identifier "two" is actually a subclasstwo!
Now, I did the homework. I digged into the code. :-)
Happens that OneToOneFields that are parent_links are marked as serialize=False, so they never get serialized! Even if you create the field manually in the model, if will still be marked as serialize=False.
Shouldn't OneToOneFields that point to parents in multi-table inheritance be serialized? Otherwise, how can you tell which subclass is the superclass in the serialized output?
What do you think? Do you think this is an issue to be resolved and, if so, can I submit a pull request?
Thanks.