#32013: TypeError: Field 'id' expected a number but got
<django.forms.models.ModelChoiceIteratorValue object at 0xdeadbeef>
---------------------------+--------------------------------------
     Reporter:  Jaap Roes  |                    Owner:  nobody
         Type:  Bug        |                   Status:  new
    Component:  Forms      |                  Version:  3.1
     Severity:  Normal     |               Resolution:
     Keywords:             |             Triage Stage:  Unreviewed
    Has patch:  0          |      Needs documentation:  0
  Needs tests:  0          |  Patch needs improvement:  0
Easy pickings:  0          |                    UI/UX:  0
---------------------------+--------------------------------------

Comment (by Jaap Roes):

 I guess this is technically documented here
 
https://docs.djangoproject.com/en/3.1/ref/forms/fields/#django.forms.ModelChoiceIteratorValue
 and in the release notes (under the //Minor features// heading).

 Replacing the `obj = SomeModel.objects.get(pk=k)` line with `obj =
 k.instance` fixes the issue (and avoids a lookup).

 However, it's not a very graceful way of discovering this new feature
 (luckily we have pretty good coverage in our test suite).

 I'm not sure if this is fixable. Maybe it's possible to somehow proxy to
 the `value` attribute when evaluating a `ModelChoiceIteratorValue` in the
 the context of a database lookup?

 At the very least this should be listed under the //Backwards
 incompatible// heading in the Django 3.1 release notes.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32013#comment:1>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/063.a444bd1b93cd208609dc86f91640d59c%40djangoproject.com.

Reply via email to