django-polymorphic icon indicating copy to clipboard operation
django-polymorphic copied to clipboard

Problems with multiple concrete inheritance

Open ozgurakcali opened this issue 5 years ago • 0 comments

With the following model structure:

class BaseRegular(models.Model):
    model_id = AutoField(primary_key=True)
    ...

class BasePolymorphic(PolymorphicModel):
    ...

class MyModel(BasePolymorphic, BaseRegular):
    ...

When trying to delete an instance of MyModel, a DoesNotExist exception is thrown. I've tracked the issue down to this piece of code in PolymorphicModel's init method:

def accessor_function(self):
    attr = model._base_objects.get(pk=self.pk)
    return attr

When the model is BaseRegular here, self.pk is MyModel instance's pk, but that's not the primary key for BaseRegular model. Do not know if other places in code assume all parents sharing the same pk.

ozgurakcali avatar Dec 12 '19 10:12 ozgurakcali