#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      |       Keywords:
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  0
                  UI/UX:  0           |
--------------------------------------+------------------------
 I'm upgrading a project from Django 3.0 to Django 3.1. Running the tests
 shows 3 unexpected errors. All are the same `TypeError: Field 'id'
 expected a number but got <django.forms.models.ModelChoiceIteratorValue
 object at 0xdeadbeef>`

 I can trace this back to this code in the `__init__` of a `ModelForm`.

 {{{
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     field = self.fields["some_fk_field"]

     new_choices = []
     for k, v in field.choices:
         do_add = True

         if not k:
             new_choices.append((k, v))
             continue

         obj = SomeModel.objects.get(pk=k)  # *CRASH*

         [...snip a bunch logic...]

         if do_add:
             new_choices.append((k, v))

     field.choices = new_choices
 }}}

 We've recently inherited this code, added tests and upgraded all the way
 from 1.4 to 3.0. This bit of code worked in all previous versions but has
 started raising errors in 3.1.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32013>
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/048.41cddc1fb11380b8e74df4a2c2a09fe5%40djangoproject.com.

Reply via email to