Skip to content

Commit dce3854

Browse files
authored
Support UUID (#329)
* Add support for UUID
1 parent 2bf66f3 commit dce3854

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

mssql/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
124124
'SmallIntegerField': 'smallint',
125125
'TextField': 'nvarchar(max)',
126126
'TimeField': 'time',
127-
'UUIDField': 'char(32)',
127+
'UUIDField': 'uniqueidentifier',
128128
}
129129
data_types_suffix = {
130130
'AutoField': 'IDENTITY (1, 1)',
@@ -376,7 +376,6 @@ def get_new_connection(self, conn_params):
376376
break
377377
if not need_to_retry:
378378
raise
379-
380379
# Handling values from DATETIMEOFFSET columns
381380
# source: https://github.com/mkleehammer/pyodbc/wiki/Using-an-Output-Converter-function
382381
conn.add_output_converter(SQL_TIMESTAMP_WITH_TIMEZONE, handle_datetimeoffset)
@@ -431,6 +430,9 @@ def init_connection_state(self):
431430
if (options.get('return_rows_bulk_insert', False)):
432431
self.features_class.can_return_rows_from_bulk_insert = True
433432

433+
if (options.get('has_native_uuid_field', True)):
434+
Database.native_uuid = True
435+
434436
val = self.get_system_datetime
435437
if isinstance(val, str):
436438
raise ImproperlyConfigured(

mssql/features.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
2222
has_json_object_function = False
2323
has_json_operators = False
2424
has_native_json_field = False
25-
has_native_uuid_field = False
25+
has_native_uuid_field = True
2626
has_real_datatype = True
2727
has_select_for_update = True
2828
has_select_for_update_nowait = True
@@ -64,6 +64,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
6464
supports_stored_generated_columns = True
6565
supports_virtual_generated_columns = True
6666

67+
6768
@cached_property
6869
def has_zoneinfo_database(self):
6970
with self.connection.cursor() as cursor:

mssql/operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def convert_floatfield_value(self, value, expression, connection):
129129

130130
def convert_uuidfield_value(self, value, expression, connection):
131131
if value is not None:
132-
value = uuid.UUID(value)
132+
value = uuid.UUID(str(value))
133133
return value
134134

135135
def convert_booleanfield_value(self, value, expression, connection):

0 commit comments

Comments
 (0)