Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#17140 closed Bug (duplicate)

Unexpected behaviour with on_delete handlers and proxy models (IntegrityError)

Reported by: jaap3 Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords: ForeignKey on_delete proxy model IntegrityError CASCADE SET_NULL
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Let's say I have a File model and an Image model. The second one being a proxy to the File model, with some additional methods and a manager that only return image-like files.

Another model has a ForeignKey to the Image model. Deleting an Image will trigger the on_delete handlers of it's foreign keys, cascades happen and everything is fine.

Deleting the same thing as an instance of File however will not clean up every objects linking to it. Instead an IntegrityError is raised. It's obvious that the File doesn't know it's also an Image and therefore doesn't trigger the on_delete handler of foreign keys referring to it by a different name.

I don't really see a nice way to work around or fix this problem.

Attachments (1)

proxy_bug.zip (1.7 KB) - added by jaap3 4 years ago.
Testcase

Download all attachments as: .zip

Change History (5)

comment:1 Changed 4 years ago by jaap3

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This seems related (but in reverse) to ticket #16128

comment:2 Changed 4 years ago by carljm

  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by jaap3

Testcase

comment:3 Changed 4 years ago by carljm

  • Resolution set to duplicate
  • Status changed from new to closed

I'm not sure I see how this is the reverse of #16128. If I'm reading that one right, the failure is in the exact same case: FK pointing to proxy model, real parent of proxy deleted. I think this is a duplicate of that ticket.

comment:4 Changed 4 years ago by jaap3

Yes, it seems to be a duplicate. I think I got confused after reading the comments and the patches of the other ticket.

I've expended my testcases to include the proxy of proxy case, and will attach it to the other bug. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top