Skip to content
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

CASCADE deletion of model with nested polymorphic models fail with xxx_ptr does not exist error #608

Open
DanSheps opened this issue Jun 14, 2024 · 0 comments

Comments

@DanSheps
Copy link

I have the following mdels:


class PolyDevice(Model):
    name = CharField(max_length=64)

class NotPolyInterface(PolymorphicModel):
    name = CharField(max_length=64)
    device = ForeignKey(to=PolyDevice, on_delete=CASCADE)
    ethernety_stuff = CharField(max_length=64)
    modular_stuff = CharField(max_length=64)
    fixed_stuff = CharField(max_length=64)
    wirelessy_stuff = CharField(max_length=64)
    fc_stuff = CharField(max_length=64)

class PolyInterface(PolymorphicModel):
    name = CharField(max_length=64)
    device = ForeignKey(to=PolyDevice, on_delete=CASCADE)

class PolyEthernetInterface(PolyInterface):
    ethernety_stuff = CharField(max_length=64)

class PolyModularInterface(PolyEthernetInterface):
    modular_stuff = CharField(max_length=64)

class PolyFixedInterface(PolyEthernetInterface):
    fixed_stuff = CharField(max_length=64)

class PolyWirelessInterface(PolyInterface):
    wirelessy_stuff = CharField(max_length=64)

class PolyFCInterface(PolyInterface):
    fc_stuff = CharField(max_length=64)

When I initialize a device and then initialize one of each type of interface (Fixed, Modular, Wireless, FC) and then attempt to delete the device, I receive the following error:

>>> PolyDevice.objects.first().delete()
Traceback (most recent call last):
  File "C:\Users\dan\AppData\Local\Programs\Python\Python310\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "C:\Development\test\venv\lib\site-packages\django\db\models\base.py", line 1131, in delete
    collector.collect([self], keep_parents=keep_parents)
  File "C:\Development\test\venv\lib\site-packages\django\db\models\deletion.py", line 350, in collect
    on_delete(self, field, sub_objs, self.using)
  File "C:\Development\test\venv\lib\site-packages\django\db\models\deletion.py", line 23, in CASCADE
    collector.collect(
  File "C:\Development\test\venv\lib\site-packages\django\db\models\deletion.py", line 298, in collect
    parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
  File "C:\Development\test\venv\lib\site-packages\django\db\models\deletion.py", line 298, in <listcomp>
    parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
AttributeError: 'PolyWirelessInterface' object has no attribute 'polyethernetinterface_ptr'. Did you mean: 'polyethernetinterface'?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant