Opened 11 years ago

Closed 11 years ago

#21467 closed Uncategorized (wontfix)

get_object_or_404 on model instance raise ValueError

Reported by: Vitaliy Yelnik Owned by: nobody
Component: Utilities Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

from django.shortcuts import get_object_or_404
from django.db.models.base import ModelBase
from django.contrib.contenttypes.models import ContentType

def test_get_object_or_404():
    # print "True"
    print isinstance(ContentType, ModelBase)

    # print False
    print isinstance(ContentType(), ModelBase)

    # print "<ContentType: content type>"
    print get_object_or_404(ContentType, id=1)

    # raise ValueError: Object is of type 'ContentType', but must be a Django Model, Manager, or QuerySet
    print get_object_or_404(ContentType(), id=1)

In Django 1.4 exception does not occur.

Change History (1)

comment:1 by Tim Graham, 11 years ago

Resolution: wontfix
Status: newclosed

If passing a model instanced actually worked in the past, it was undocumented behavior (see Required Arguments of get_object_or_404 and I don't think we're going to make a change to restore that behavior. The change was ticket #19432.

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