diff --git a/mssql/base.py b/mssql/base.py index f0be847..033660c 100644 --- a/mssql/base.py +++ b/mssql/base.py @@ -124,7 +124,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): 'SmallIntegerField': 'smallint', 'TextField': 'nvarchar(max)', 'TimeField': 'time', - 'UUIDField': 'char(32)', + 'UUIDField': 'uniqueidentifier', } data_types_suffix = { 'AutoField': 'IDENTITY (1, 1)', @@ -376,7 +376,6 @@ def get_new_connection(self, conn_params): break if not need_to_retry: raise - # Handling values from DATETIMEOFFSET columns # source: https://github.com/mkleehammer/pyodbc/wiki/Using-an-Output-Converter-function conn.add_output_converter(SQL_TIMESTAMP_WITH_TIMEZONE, handle_datetimeoffset) @@ -431,6 +430,9 @@ def init_connection_state(self): if (options.get('return_rows_bulk_insert', False)): self.features_class.can_return_rows_from_bulk_insert = True + if (options.get('has_native_uuid_field', True)): + Database.native_uuid = True + val = self.get_system_datetime if isinstance(val, str): raise ImproperlyConfigured( diff --git a/mssql/features.py b/mssql/features.py index c215807..b2480f5 100644 --- a/mssql/features.py +++ b/mssql/features.py @@ -22,7 +22,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): has_json_object_function = False has_json_operators = False has_native_json_field = False - has_native_uuid_field = False + has_native_uuid_field = True has_real_datatype = True has_select_for_update = True has_select_for_update_nowait = True @@ -64,6 +64,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_stored_generated_columns = True supports_virtual_generated_columns = True + @cached_property def has_zoneinfo_database(self): with self.connection.cursor() as cursor: diff --git a/mssql/operations.py b/mssql/operations.py index b83305a..6a00c83 100644 --- a/mssql/operations.py +++ b/mssql/operations.py @@ -129,7 +129,7 @@ def convert_floatfield_value(self, value, expression, connection): def convert_uuidfield_value(self, value, expression, connection): if value is not None: - value = uuid.UUID(value) + value = uuid.UUID(str(value)) return value def convert_booleanfield_value(self, value, expression, connection):