Check for None on real_model in get_real_instance#632
Conversation
|
@nlsfnr how did this situation arise? |
|
Slightly weird scenario -- I use Docker containers for local development with a persitent volume for the DB. When switching between branches, where one branch has a new subclass of a polymorphic model that the other branch does not, the ContentType for said subclass still exists in the DB's volume but does not correspond to a Django model in the code base. That means that It's more or less equivalent to removing a Django model from the code base without adding the appropriate migration. |
|
My only hesitation is that this might hide when something else is very wrong, like having unapplied migrations or other edge cases. I'm new to this project and still not the officially blessed maintainer so I'll revisit this when a decision is made on that. thanks! |
|
Yes good point. I was mostly matching what was best for my use case, but looking at the implementation of If downstream applications prefer returning self, they could simply overwrite Happy to change the PR accordingly. |
|
PolymorphicTypeInvalid certainly seems appropriate. |
Fixes a bug where
PolymorphicModel'sget_real_instance()raises an exception whenget_real_instance_class()returns None.