Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#15274 closed (fixed)

UpdateView raises exception about overiding get_object

Reported by: sergeybe@… Owned by: nobody
Component: Generic views Version: 1.3-beta
Severity: Keywords: blocker
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I've defined the view class:

class OneAuthorUpdate(generic.UpdateView):

    def get_object(self):
        return Author.objects.get(pk=1)

But next exception raises:

ImproperlyConfigured: OneAuthorUpdate is missing a queryset. Define OneAuthorUpdate.model, OneAuthorUpdate.queryset, or override OneAuthorUpdate.get_object()

Attachments (1)

tests_for_get_object.patch (3.8 KB) - added by Sergey N. Belinsky <sergeybe@…> 6 years ago.
Tests for UpdateView and get_object method

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by Sergey N. Belinsky <sergeybe@…>

Attachment: tests_for_get_object.patch added

Tests for UpdateView and get_object method

comment:1 Changed 6 years ago by Russell Keith-Magee

Keywords: blocker added
milestone: 1.3
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Confirmed that the test case fails as described; need to dig in closer to see exactly why. Marking as a blocker for the moment, because at the very least, it's confusing.

comment:2 Changed 6 years ago by Russell Keith-Magee

I've found the cause -- you've overridden get_object, but you haven't provided a form, so the call to get_form_class() is calling get_queryset() as a cheats way to find the model that can be used to automatically construct a ModelForm.

The simple workaround -- specify a form_class. I'm looking into what we can do as a permanent solution.

comment:3 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

In [15540]:

Fixed #15247 -- Ensured that if a SingleObject? view defines get_object but not get_queryset, the ModelFormMixin? doesn't fail. Thanks to Sergey N. Belinsky for the report and test case.

(Fat fingers attributed this to the wrong ticket)

comment:4 Changed 6 years ago by Sergey N. Belinsky <sergeybe@…>

It works now. Thank you!

comment:5 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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