problems with UUID as pk for CustomUser
duckheada opened this issue · comments
Duck_Heada commented
Found a bug? Please fill out the sections below.
Issue Summary
Amongst other errors:
Exception Type: NoReverseMatch at /oscar/dashboard/users/
Exception Value: Reverse for 'user-detail' with arguments '(UUID('0ffdd59b-51ce-471c-a0cd-f9fa85d6299a'),)' not found. 1 pattern(s) tried: ['oscar/dashboard/users/(?P-?\d+)/$']
Steps to Reproduce
- create custom user:
class CustomUser(AbstractUser):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
- after migrations, visit: http://127.0.0.1:8000/oscar/dashboard/users/
Technical details
- Python version: 3.9
- Django version: 2.2
- Oscar version: 3.2
Viggo de Vries commented
Hi, this is no bug. You changed the unique identifier. The url requires a number in the end, not an uuid.
You could fix this by adding your own url that points to the same. Something like:
from oscar.core.loadin import get_class
UserDetailView = get_class("dashboard.users.views", "UserDetailView")
path(
r"oscar/dashboard/users/(?P<pk>[0-9a-f-]+)/$", UserDetailView.as_view(), name="user-detail"
),
The regex probably doesn't work so you will need to figure that out on your own.