Commit ed782123 authored by Marc Tamlyn's avatar Marc Tamlyn
Browse files

Fixed #19463 -- Added UUIDField

Uses native support in postgres, and char(32) on other backends.
parent 0d1561d1
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ from __future__ import unicode_literals
import datetime
import re
import sys
import uuid
import warnings

try:
@@ -398,6 +399,8 @@ class DatabaseOperations(BaseDatabaseOperations):
        converters = super(DatabaseOperations, self).get_db_converters(internal_type)
        if internal_type in ['BooleanField', 'NullBooleanField']:
            converters.append(self.convert_booleanfield_value)
        if internal_type == 'UUIDField':
            converters.append(self.convert_uuidfield_value)
        return converters

    def convert_booleanfield_value(self, value, field):
@@ -405,6 +408,11 @@ class DatabaseOperations(BaseDatabaseOperations):
            value = bool(value)
        return value

    def convert_uuidfield_value(self, value, field):
        if value is not None:
            value = uuid.UUID(value)
        return value


class DatabaseWrapper(BaseDatabaseWrapper):
    vendor = 'mysql'
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ class DatabaseCreation(BaseDatabaseCreation):
        'SmallIntegerField': 'smallint',
        'TextField': 'longtext',
        'TimeField': 'time',
        'UUIDField': 'char(32)',
    }

    def sql_table_creation_suffix(self):
+8 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import decimal
import re
import platform
import sys
import uuid
import warnings


@@ -264,6 +265,8 @@ WHEN (new.%(col_name)s IS NULL)
            converters.append(self.convert_datefield_value)
        elif internal_type == 'TimeField':
            converters.append(self.convert_timefield_value)
        elif internal_type == 'UUIDField':
            converters.append(self.convert_uuidfield_value)
        converters.append(self.convert_empty_values)
        return converters

@@ -310,6 +313,11 @@ WHEN (new.%(col_name)s IS NULL)
            value = value.time()
        return value

    def convert_uuidfield_value(self, value, field):
        if value is not None:
            value = uuid.UUID(value)
        return value

    def deferrable_sql(self):
        return " DEFERRABLE INITIALLY DEFERRED"

+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ class DatabaseCreation(BaseDatabaseCreation):
        'TextField': 'NCLOB',
        'TimeField': 'TIMESTAMP',
        'URLField': 'VARCHAR2(%(max_length)s)',
        'UUIDField': 'VARCHAR2(32)',
    }

    data_type_check_constraints = {
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ from django.utils.timezone import utc
try:
    import psycopg2 as Database
    import psycopg2.extensions
    import psycopg2.extras
except ImportError as e:
    from django.core.exceptions import ImproperlyConfigured
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
@@ -33,6 +34,7 @@ psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
psycopg2.extensions.register_adapter(SafeBytes, psycopg2.extensions.QuotedString)
psycopg2.extensions.register_adapter(SafeText, psycopg2.extensions.QuotedString)
psycopg2.extras.register_uuid()


def utc_tzinfo_factory(offset):
Loading