django-oscar / django-oscar

Domain-driven e-commerce for Django

Home Page:http://oscarcommerce.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

problems with UUID as pk for CustomUser

duckheada opened this issue · comments

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

  1. create custom user:
class CustomUser(AbstractUser):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
  1. 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

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.