#20044 closed Bug (invalid)
DatabaseError at /admin/: custom user model with UUID PK
Reported by: | Alexander Ovchinnikov | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.5 |
Severity: | Normal | Keywords: | admin, user, uuid |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I use Django 1.5 with custom user model and uuid as primary key,
uuid = UUIDField(version=1, auto=True, primary_key=True)
When staff user try to login (and if he/she is not superadmin) - database error:
DatabaseError at /admin/ operator does not exist: uuid = numeric LINE 1: ...."id") WHERE "itresumebase_user_groups"."user_id" = 32316155... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
My Postgres log, sudo cat postgresql-9.1-main.log:
... ... 2013-03-14 00:07:10 UTC ERROR: current transaction is aborted, commands ignored until end of transaction block 2013-03-14 00:07:10 UTC STATEMENT: SELECT "django_content_type"."app_label", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "auth_group_permissions" ON ("auth_permission"."id" = "auth_group_permissions"."permission_id") INNER JOIN "auth_group" ON ("auth_group_permissions"."group_id" = "auth_group"."id") INNER JOIN "itresumebase_user_groups" ON ("auth_group"."id" = "itresumebase_user_groups"."group_id") INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "itresumebase_user_groups"."user_id" = 32316155710099430392310223565998026040 LIMIT 21
32316155710099430392310223565998026040 ? What is it? User uuid is '184fdd7d-8c37-11e2-bb51-002241246d38'...
Environment: Request Method: GET Request URL: http://it-resume.ru:8000/admin/ Django Version: 1.5 Python Version: 2.7.3 Installed Applications: (u'cities_light', u'django.contrib.auth', u'django.contrib.contenttypes', u'django.contrib.sessions', u'django.contrib.sites', u'django.contrib.messages', u'django.contrib.staticfiles', u'django.contrib.admin', u'django.contrib.admindocs', u'redactor', u'itresumebase', u'south', u'autocomplete_light', u'guardian', u'social_auth') Installed Middleware: (u'django.middleware.common.CommonMiddleware', u'django.contrib.sessions.middleware.SessionMiddleware', u'django.middleware.csrf.CsrfViewMiddleware', u'django.contrib.auth.middleware.AuthenticationMiddleware', u'django.contrib.messages.middleware.MessageMiddleware') Traceback: File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 115. response = callback(request, *callback_args, **callback_kwargs) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper 219. return self.admin_view(view, cacheable)(*args, **kwargs) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, *args, **kwargs) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 89. response = view_func(request, *args, **kwargs) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner 202. return view(request, *args, **kwargs) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 89. response = view_func(request, *args, **kwargs) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/admin/sites.py" in index 346. has_module_perms = user.has_module_perms(app_label) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/auth/models.py" in has_module_perms 367. return _user_has_module_perms(self, app_label) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/auth/models.py" in _user_has_module_perms 288. if backend.has_module_perms(user, app_label): File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/auth/backends.py" in has_module_perms 59. for perm in self.get_all_permissions(user_obj): File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/auth/backends.py" in get_all_permissions 45. user_obj._perm_cache.update(self.get_group_permissions(user_obj)) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/contrib/auth/backends.py" in get_group_permissions 37. user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms]) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/models/query.py" in _result_iter 123. self._fill_cache() File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/models/query.py" in _fill_cache 939. self._result_cache.append(next(self._iter)) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/models/query.py" in _safe_iterator 344. for item in iterator: File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/models/query.py" in iterator 1141. for row in self.query.get_compiler(self.db).results_iter(): File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter 775. for rows in self.execute_sql(MULTI): File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql 840. cursor.execute(sql, params) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/backends/util.py" in execute 41. return self.cursor.execute(sql, params) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py" in execute 58. six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) File "/Users/lorddaedra/Envs/itresume/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py" in execute 54. return self.cursor.execute(query, args) Exception Type: DatabaseError at /admin/ Exception Value: operator does not exist: uuid = numeric LINE 1: ...."id") WHERE "itresumebase_user_groups"."user_id" = 32316155... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Change History (4)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
According to the documentation (https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#specifying-a-custom-user-model), one of the conditions for a custom User model is "Your model must have an integer primary key."
It seems the UUID field implementation you are using is this one: https://github.com/dcramer/django-uuidfield and its README reads: "This acts as a char(32) to maintain compatibility with SQL versions"
comment:3 by , 12 years ago
For the record, I'm interested in lifting this limitation -- see ticket #14881
comment:4 by , 12 years ago
I also tried UUID field from django-pgfields (https://github.com/jpwatts/django-pgfields/blob/master/pgfields/db/models/fields.py#L56 ) with same result (error, operator does not exist: uuid = numeric).
It use uuid type for Postgres (http://www.postgresql.org/docs/devel/static/datatype-uuid.html).
I'm interested in lifting this limitation too.
I like UUID and going to use it as PK in any models (it has some advantages, you know about it, some projects like Couchbase use it, also sometimes it's good for marketing reasons, it helps to hide how small is our database. :-) So it's good case for startups, where first users will see ID in links (like /tasks/121/ or /tasks/475a5bdc-8cc9-11e2-a66c-002241246d38/)
So I do not agitate you to make all PK in all models with UUID type by default, but please give us ability do not switch to Pyramid and use this feature with Django via additional apps. :-)
(itresume)Alexander-iMac:itresume lorddaedra$ pip freeze