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

Fix: UUID field support #54

Merged
merged 4 commits into from Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions django_redshift_backend/base.py
Expand Up @@ -36,6 +36,7 @@ class DatabaseFeatures(BasePGDatabaseFeatures):
supports_column_check_constraints = False
can_distinct_on_fields = False
allows_group_by_selected_pks = False
has_native_uuid_field = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



class DatabaseOperations(BasePGDatabaseOperations):
Expand Down
2 changes: 1 addition & 1 deletion doc/dev.rst
Expand Up @@ -20,7 +20,7 @@ Setup development environment
* Requires supported Python version
* do setup under django-redshift-backend.git repository root as::

$ pip install -U pip setuptools wheel setuotools_scm
$ pip install -U pip setuptools wheel setuptools_scm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've applied this line at ff5c1cb

$ pip install -r dev-requires.txt

Testing
Expand Down
14 changes: 14 additions & 0 deletions tests/test_redshift_backend.py
Expand Up @@ -70,6 +70,20 @@ def test_annotate(self):
sql = norm_sql(compiler.as_sql()[0])
self.assertEqual(sql, expected_dml_annotate)

def test_insert_uuid_field(self):
import uuid
from django.db.models import sql
from testapp.models import TestModel
obj = TestModel(uuid=uuid.uuid4())
q = sql.InsertQuery(obj)
q.insert_values(obj._meta.local_fields, [obj])
statements = q.get_compiler('default').as_sql()
# uuid is the last field of TestModel
uuid_insert_value = statements[0][1][-1]
# the Python value for insertion must be a string whose length is 32
self.assertEqual(type(uuid_insert_value), str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

self.assertEqual(len(uuid_insert_value), 32)


class MigrationTest(unittest.TestCase):

Expand Down