#36846: ContentType.get_object_for_this_type() does not handle removed models
--------------------------+------------------------------------------------
     Reporter:  mthuurne  |                     Type:  Bug
       Status:  new       |                Component:  contrib.contenttypes
      Version:  dev       |                 Severity:  Normal
     Keywords:            |             Triage Stage:  Unreviewed
    Has patch:  0         |      Needs documentation:  0
  Needs tests:  0         |  Patch needs improvement:  0
Easy pickings:  0         |                    UI/UX:  0
--------------------------+------------------------------------------------
 When asked for an object for which the model no longer exists,
 `ContentType.get_object_for_this_type()` will raise this exception:
 {{{
 AttributeError: 'NoneType' object has no attribute '_base_manager'
 }}}

 The reason for this is that the `model_class()` method will return `None`
 when the model cannot be found and the implementation of
 `get_object_for_this_type()` does not check for that:
 {{{#!python
 return self.model_class()._base_manager.using(using).get(**kwargs)
 }}}

 The behavior I'd expect is that `ObjectDoesNotExist` would be raised,
 similar to the situation where the model does exist but the object does
 not.

 I first noticed this bug in Django 4.2.27, but the latest code in Git has
 the same issue.

 If raising `ObjectDoesNotExist` is indeed the desired solution, I can
 provide a patch for that.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36846>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019b941e3370-92a053a6-b840-4f81-be7a-031052ce1257-000000%40eu-central-1.amazonses.com.

Reply via email to