{"action":"created","issue":{"url":"https://api.github.com/repos/chrisglass/django_polymorphic/issues/160","repository_url":"https://api.github.com/repos/chrisglass/django_polymorphic","labels_url":"https://api.github.com/repos/chrisglass/django_polymorphic/issues/160/labels{/name}","comments_url":"https://api.github.com/repos/chrisglass/django_polymorphic/issues/160/comments","events_url":"https://api.github.com/repos/chrisglass/django_polymorphic/issues/160/events","html_url":"https://github.com/chrisglass/django_polymorphic/issues/160","id":108283544,"number":160,"title":"Cascading bug on deletion (Django 1.8)","user":{"login":"martinmaillard","id":1334124,"avatar_url":"https://avatars.githubusercontent.com/u/1334124?v=3","gravatar_id":"","url":"https://api.github.com/users/martinmaillard","html_url":"https://github.com/martinmaillard","followers_url":"https://api.github.com/users/martinmaillard/followers","following_url":"https://api.github.com/users/martinmaillard/following{/other_user}","gists_url":"https://api.github.com/users/martinmaillard/gists{/gist_id}","starred_url":"https://api.github.com/users/martinmaillard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinmaillard/subscriptions","organizations_url":"https://api.github.com/users/martinmaillard/orgs","repos_url":"https://api.github.com/users/martinmaillard/repos","events_url":"https://api.github.com/users/martinmaillard/events{/privacy}","received_events_url":"https://api.github.com/users/martinmaillard/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-25T08:23:50Z","updated_at":"2016-02-17T12:38:01Z","closed_at":null,"body":"I have something similar to the following situation:\r\n\r\n        A ------- B                 \r\n                /   \\\r\n              B1     B2 ------- C\r\n\r\nIn code:\r\n\r\n    class A(models.Model):\r\n        pass\r\n\r\n    class B(polymorphic.PolymorphicModel):\r\n        a = models.ForeignKey(A)\r\n\r\n    class B1(B):\r\n        pass\r\n\r\n    class B2(B):\r\n        pass\r\n\r\n    class C(models.Model):\r\n        b = models.ForeignKey(B1)\r\n\r\nIf I tried to delete an `A`, the following error occurs:\r\n\r\n    ValueError: Cannot query \"B2 object\": Must be \"B1\" instance.\r\n\r\nThe full example and traceback:\r\n\r\n    a = A.objects.create()\r\n    b1 = B1.objects.create(a=a)\r\n    b2 = B2.objects.create(a=a)\r\n    c = C.objects.create(b=b1)\r\n\r\n    a.delete()\r\n\r\n    File \"[...]/text.py\", line 137, in test_cascading_bug\r\n      a.delete()\r\n    File \"[...]/django/db/models/base.py\", line 895, in delete\r\n      collector.collect([self])\r\n    File \"[...]/django/db/models/deletion.py\", line 229, in collect\r\n      field.rel.on_delete(self, field, sub_objs, self.using)\r\n    File \"[...]/django/db/models/deletion.py\", line 18, in CASCADE\r\n      source_attr=field.name, nullable=field.null)\r\n    File \"[...]/django/db/models/deletion.py\", line 225, in collect\r\n      sub_objs = self.related_objects(related, batch)\r\n    File \"[...]/django/db/models/deletion.py\", line 247, in related_objects\r\n      **{\"%s__in\" % related.field.name: objs}\r\n    File \"[...]/django/db/models/query.py\", line 679, in filter\r\n      return self._filter_or_exclude(False, *args, **kwargs)\r\n    File \"[...]/django/db/models/query.py\", line 697, in _filter_or_exclude\r\n      clone.query.add_q(Q(*args, **kwargs))\r\n    File \"[...]/django/db/models/sql/query.py\", line 1309, in add_q\r\n      clause, require_inner = self._add_q(where_part, self.used_aliases)\r\n    File \"[...]/django/db/models/sql/query.py\", line 1337, in _add_q\r\n      allow_joins=allow_joins, split_subq=split_subq,\r\n    File \"[...]/django/db/models/sql/query.py\", line 1178, in build_filter\r\n      self.check_related_objects(field, value, opts)\r\n    File \"[...]/django/db/models/sql/query.py\", line 1076, in check_related_objects\r\n      self.check_query_object_type(v, opts)\r\n    File \"[...]/django/db/models/sql/query.py\", line 1057, in check_query_object_type\r\n      (value, opts.object_name))\r\n    ValueError: Cannot query \"B2 object\": Must be \"B1\" instance.\r\n\r\nI'm not 100% sure it is caused by django-polymorphic, but I could not reproduce the error without it...\r\n"},"comment":{"url":"https://api.github.com/repos/chrisglass/django_polymorphic/issues/comments/185181335","html_url":"https://github.com/chrisglass/django_polymorphic/issues/160#issuecomment-185181335","issue_url":"https://api.github.com/repos/chrisglass/django_polymorphic/issues/160","id":185181335,"user":{"login":"vdboor","id":200303,"avatar_url":"https://avatars.githubusercontent.com/u/200303?v=3","gravatar_id":"","url":"https://api.github.com/users/vdboor","html_url":"https://github.com/vdboor","followers_url":"https://api.github.com/users/vdboor/followers","following_url":"https://api.github.com/users/vdboor/following{/other_user}","gists_url":"https://api.github.com/users/vdboor/gists{/gist_id}","starred_url":"https://api.github.com/users/vdboor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vdboor/subscriptions","organizations_url":"https://api.github.com/users/vdboor/orgs","repos_url":"https://api.github.com/users/vdboor/repos","events_url":"https://api.github.com/users/vdboor/events{/privacy}","received_events_url":"https://api.github.com/users/vdboor/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T12:38:01Z","updated_at":"2016-02-17T12:38:01Z","body":"@bonniejools I'm curious what you've overwritten. Does the issue also occur on standard Django models, or only when the polymorphic models/managers are used?"}}