Skip to content

Commit

Permalink
Support UUID (#329)
Browse files Browse the repository at this point in the history
* Add support for UUID
  • Loading branch information
dauinsight authored Feb 9, 2024
1 parent 2bf66f3 commit dce3854
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mssql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion mssql/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion mssql/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit dce3854

Please sign in to comment.