#29449: Regression in UserCreationForm (and UserChangeForm) for custom user models -------------------------------------+------------------------------------- Reporter: Sławek Ehlert | Owner: nobody Type: Bug | Status: new Component: contrib.auth | Version: 2.1 Severity: Release blocker | Resolution: Keywords: auth forms | Triage Stage: Accepted UserCreationForm UserChangeForm | Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Sławek Ehlert): I've added some explicit tests in [https://github.com/django/django/pull/10020 PR#10020]. Unfortunately it causes more failures than the ones I've introduced with those new tests there. What happens is: - the test I've added overrides the {{{AUTH_USER_MODEL}}} setting with a model that has a FK as a username field ({{{auth_tests.CustomUserWithFK}}}). - the test fails on the {{{override_settings}}} part already, since the {{{reload_auth_forms}}} receiver fails to reload the {{{django.contrib.auth.forms}}} module with that user model in place (fails with a similar {{{TypeError}}} that refers to 'limit_choices_to' argument when trying to instantiate the {{{UsernameField}}})[*] - because of the {{{override_settings}}} bug (see #29467) other tests still see the {{{auth_tests.CustomUserWithFK}}} as a current user model. [*] - the exact traceback for the mentioned error is: {{{ ====================================================================== ERROR: test_custom_form_username_not_charfield (auth_tests.test_forms.UserChangeFormTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor yield File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run testMethod() File "/Users/slafs/testing/django/django/django/test/utils.py", line 364, in inner with self as context: File "/Users/slafs/testing/django/django/django/test/utils.py", line 336, in __enter__ return self.enable() File "/Users/slafs/testing/django/django/django/test/utils.py", line 405, in enable setting=key, value=new_value, enter=True) File "/Users/slafs/testing/django/django/django/dispatch/dispatcher.py", line 175, in send for receiver in self._live_receivers(sender) File "/Users/slafs/testing/django/django/django/dispatch/dispatcher.py", line 175, in <listcomp> for receiver in self._live_receivers(sender) File "/Users/slafs/testing/django/django/tests/auth_tests/test_forms.py", line 38, in reload_auth_forms reload(django.contrib.auth.forms) File "/Users/slafs/.virtualenvs/django/lib/python3.6/importlib/__init__.py", line 166, in reload _bootstrap._exec(spec, module) File "<frozen importlib._bootstrap>", line 618, in _exec File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/slafs/testing/django/django/django/contrib/auth/forms.py", line 63, in <module> class UserCreationForm(forms.ModelForm): File "/Users/slafs/testing/django/django/django/forms/models.py", line 256, in __new__ apply_limit_choices_to=False, File "/Users/slafs/testing/django/django/django/forms/models.py", line 172, in fields_for_model formfield = f.formfield(**kwargs) File "/Users/slafs/testing/django/django/django/db/models/fields/related.py", line 956, in formfield **kwargs, File "/Users/slafs/testing/django/django/django/db/models/fields/related.py", line 418, in formfield return super().formfield(**defaults) File "/Users/slafs/testing/django/django/django/db/models/fields/__init__.py", line 890, in formfield return form_class(**defaults) File "/Users/slafs/testing/django/django/django/forms/fields.py", line 213, in __init__ super().__init__(**kwargs) TypeError: __init__() got an unexpected keyword argument 'limit_choices_to' }}} -- Ticket URL: <https://code.djangoproject.com/ticket/29449#comment:2> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.2fe9d1a042adc9d4f4cdf00260b4f4eb%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.