Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUIDField support: How does it work? #53

Closed
nockty opened this issue Nov 15, 2018 · 0 comments · Fixed by #54
Closed

UUIDField support: How does it work? #53

nockty opened this issue Nov 15, 2018 · 0 comments · Fixed by #54

Comments

@nockty
Copy link
Contributor

nockty commented Nov 15, 2018

Subject: When using UUIDField: django.db.utils.ProgrammingError: type "uuid" does not exist

Problem

Procedure to reproduce the problem

  • Create a model which uses django.db.models.UUIDField
class SomeModel:
    uuid = models.UUIDField(default=uuid.uuid4, editable=False)
    # some other fields
  • Try to save an instance of the model.
>>> some_instance = SomeModel()
>>> some_instance.save(using='some_database')
  • My database uses django-redshift-backend:
>>> django.db.connections['some_database']
<django_redshift_backend.base.DatabaseWrapper object at 0x7f17ee6f35c0>
>>> django.db.connections['some_database'].data_types['UUIDField']
'varchar(32)'

Error logs / results

  • Traceback:
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 718, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 748, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 831, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 869, in _do_insert
    using=using, raw=raw)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1136, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1289, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: type "uuid" does not exist
  • Raw SQL query:
(0.167) INSERT INTO "someapp_somemodel" ("field1", "field2", "field3", "field4", "field5", "field6", "field7", "field8", "field9", "uuid", "field11", "field12", "field13", "field14") VALUES ('', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'unk', '7a6b990a-c24b-4146-adb7-986b3fe7724d'::uuid, '', 'json', NULL, 2);
  • Corresponding Python arguments:
args=['', None, None, None, None, None, None, None, 'unk', UUID('7a6b990a-c24b-4146-adb7-986b3fe7724d'), '', 'json', None, 2]

Expected results

I would expect that the uuid data type is not used when saving the instance in the database. Then again, maybe I'm doing things wrong and I completely miss something important when trying to use UUIDField. In this case, maybe the documentation should be updated to teach users how to use it?

Environment info

  • OS: Docker container built by using the python:3.6 image
  • Python version: 3.6.6
  • Django version: 2.1.3 (I know django-redshift-backend is not supposed to support Django2.1 yet, but then why is such an issue happening anyway?)
  • Django-Redshift-Backend version: 0.9.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant