﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32013	Field choice attribute returns different objects in forms.	Jaap Roes	nobody	"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."	Bug	closed	Forms	3.1	Normal	invalid			Unreviewed	0	0	0	0	0	0
