Skip to content

Commit

Permalink
Merge pull request #54 from nockty/fix-uuid-field-support
Browse files Browse the repository at this point in the history
Fix: UUID field support
  • Loading branch information
shimizukawa committed Jan 21, 2019
2 parents ff5c1cb + 700983f commit ed918b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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


class DatabaseOperations(BasePGDatabaseOperations):
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)
self.assertEqual(len(uuid_insert_value), 32)


class MigrationTest(unittest.TestCase):

Expand Down

0 comments on commit ed918b4

Please sign in to comment.