[Django] #36087: Add system check mentioning contrib.auth is not composite primary key ready

7 views
Skip to first unread message

Django

unread,
Jan 11, 2025, 10:16:35 PM1/11/25
to django-...@googlegroups.com
#36087: Add system check mentioning contrib.auth is not composite primary key ready
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Type:
| Cleanup/optimization
Status: new | Component:
| contrib.auth
Version: dev | 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
-------------------------------------+-------------------------------------
It may not be likely someone would try this, but even so, we might add a
system check or otherwise document that `contrib.auth` is not composite
primary key ready. Then maybe we could refocus this ticket on adding
support.

Adjusting a custom user model like this:

{{{#!diff
diff --git a/tests/auth_tests/models/custom_user.py
b/tests/auth_tests/models/custom_user.py
index 4586e452cd..0647e47ede 100644
--- a/tests/auth_tests/models/custom_user.py
+++ b/tests/auth_tests/models/custom_user.py
@@ -52,6 +52,7 @@ class CustomUserManager(BaseUserManager):


class CustomUser(AbstractBaseUser):
+ pk = models.CompositePrimaryKey("email", "date_of_birth")
email = models.EmailField(verbose_name="email address",
max_length=255, unique=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
}}}

Leads to various failures in contrib.auth that expect to deserialize a pk
by decoding to a bytestring.

The failure I was playing with was a little easier to see by doing this:
{{{#!diff
diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
index a18cfdb347..4c82a4103c 100644
--- a/django/contrib/auth/views.py
+++ b/django/contrib/auth/views.py
@@ -304,7 +304,7 @@ class PasswordResetConfirmView(PasswordContextMixin,
FormView):
user = UserModel._default_manager.get(pk=uid)
except (
TypeError,
- ValueError,
+ # ValueError,
OverflowError,
UserModel.DoesNotExist,
ValidationError,
}}}

Then...
{{{
======================================================================
ERROR: test_confirm_valid_custom_user
(auth_tests.test_views.CustomUserPasswordResetTest.test_confirm_valid_custom_user)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/.../django/tests/auth_tests/test_views.py", line 529, in
test_confirm_valid_custom_user
response = self.client.get(path)
^^^^^^^^^^^^^^^^^^^^^

...

File "/Users/.../django/django/contrib/auth/views.py", line 275, in
dispatch
self.user = self.get_user(kwargs["uidb64"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../django/django/contrib/auth/views.py", line 304, in
get_user
user = UserModel._default_manager.get(pk=uid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...
File "/Users/.../django/django/db/models/lookups.py", line 30, in
__init__
self.rhs = self.get_prep_lookup()
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../django/django/db/models/fields/tuple_lookups.py", line
36, in get_prep_lookup
self.check_rhs_is_tuple_or_list()
File "/Users/.../django/django/db/models/fields/tuple_lookups.py", line
45, in check_rhs_is_tuple_or_list
raise ValueError(
ValueError: 'exact' lookup of 'pk' must be a tuple or a list

----------------------------------------------------------------------
Ran 2 tests in 0.056s

FAILED (errors=1)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36087>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 11, 2025, 11:15:09 PM1/11/25
to django-...@googlegroups.com
#36087: Add system check mentioning contrib.auth is not composite primary key ready
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: contrib.auth | Version: dev
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
-------------------------------------+-------------------------------------
Description changed by Jacob Walls:

Old description:
New description:

It may not be likely someone would try this, but even so, we might add a
system check or otherwise document that `contrib.auth` is not composite
primary key ready (see #35953)
--
Ticket URL: <https://code.djangoproject.com/ticket/36087#comment:1>

Django

unread,
Jan 11, 2025, 11:25:46 PM1/11/25
to django-...@googlegroups.com
#36087: Add system check mentioning contrib.auth is not composite primary key ready
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: contrib.auth | Version: dev
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
-------------------------------------+-------------------------------------
Description changed by Jacob Walls:

Old description:

> It may not be likely someone would try this, but even so, we might add a
> system check or otherwise document that `contrib.auth` is not composite
primary key ready. Then we can decide on whether to add support.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/36087#comment:2>
Reply all
Reply to author
Forward
0 new messages