Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aurora_dsql_django/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._patch_autofields()

# Automatically disable server-side cursors since Aurora DSQL doesn't support them.
# We preserve the user config if it is defined but this is likely a user mistake.
self.settings_dict.setdefault('DISABLE_SERVER_SIDE_CURSORS', True)

def _patch_autofields(self):
"""
Patch AutoField classes to return UUID type for related fields.
Expand Down
65 changes: 57 additions & 8 deletions aurora_dsql_django/tests/unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ def test_autofield_to_python_uuid_conversion(self):

# Test with valid UUID string.
uuid_string = "8fcc0dd2-1d96-4428-a619-f0e43996dc19"

result_auto = autofield.to_python(uuid_string)
result_big = bigautofield.to_python(uuid_string)

# Should convert to UUID objects.
self.assertIsInstance(result_auto, uuid.UUID)
self.assertIsInstance(result_big, uuid.UUID)
Expand All @@ -230,22 +230,22 @@ def test_autofield_to_python_with_uuid_object(self):
"""Test that AutoField.to_python handles existing UUID objects."""
autofield = models.AutoField()
bigautofield = models.BigAutoField()

uuid_obj = uuid.UUID("8fcc0dd2-1d96-4428-a619-f0e43996dc19")
result_auto = autofield.to_python(uuid_obj)
result_big = bigautofield.to_python(uuid_obj)

self.assertEqual(result_auto, uuid_obj)
self.assertEqual(result_big, uuid_obj)

def test_autofield_to_python_with_none(self):
"""Test that AutoField.to_python handles None values."""
autofield = models.AutoField()
bigautofield = models.BigAutoField()

result_auto = autofield.to_python(None)
result_big = bigautofield.to_python(None)

self.assertIsNone(result_auto)
self.assertIsNone(result_big)

Expand All @@ -272,14 +272,63 @@ def test_autofield_to_python_non_uuid_type_error(self):
def test_autofield_error_message_content(self):
"""Test that AutoField validation errors contain correct UUID message."""
autofield = models.AutoField()

with self.assertRaises(ValidationError) as cm:
autofield.to_python(123)

error_message = str(cm.exception.messages[0])
self.assertIn("must be a valid UUID", error_message)
self.assertIn("123", error_message)

def test_disable_server_side_cursors_auto_set(self):
"""Test that DISABLE_SERVER_SIDE_CURSORS is automatically set to True."""
wrapper = DatabaseWrapper({
'ENGINE': 'aurora_dsql_django',
'NAME': 'test_db',
})

self.assertTrue(wrapper.settings_dict['DISABLE_SERVER_SIDE_CURSORS'])

def test_disable_server_side_cursors_respects_customer_setting(self):
"""Test that customer's DISABLE_SERVER_SIDE_CURSORS setting is not overridden."""
wrapper_false = DatabaseWrapper({
'ENGINE': 'aurora_dsql_django',
'NAME': 'test_db',

# Explicit user configuration.
'DISABLE_SERVER_SIDE_CURSORS': False,
})

# Ensure we do not override a value that conflicts with the default.
self.assertFalse(wrapper_false.settings_dict['DISABLE_SERVER_SIDE_CURSORS'])

# Test with customer setting True
wrapper_true = DatabaseWrapper({
'ENGINE': 'aurora_dsql_django',
'NAME': 'test_db',

# Explicit user configuration.
'DISABLE_SERVER_SIDE_CURSORS': True,
})

self.assertTrue(wrapper_true.settings_dict['DISABLE_SERVER_SIDE_CURSORS'])

def test_disable_server_side_cursors_with_other_options(self):
"""Test that DISABLE_SERVER_SIDE_CURSORS works with other settings."""
wrapper = DatabaseWrapper({
'ENGINE': 'aurora_dsql_django',
'NAME': 'test_db',
'OPTIONS': {
'sslmode': 'require',
'region': 'us-east-1',
}
})

# Should add DISABLE_SERVER_SIDE_CURSORS while preserving other options
self.assertTrue(wrapper.settings_dict['DISABLE_SERVER_SIDE_CURSORS'])
self.assertEqual(wrapper.settings_dict['OPTIONS']['sslmode'], 'require')
self.assertEqual(wrapper.settings_dict['OPTIONS']['region'], 'us-east-1')


if __name__ == '__main__':
unittest.main()
Loading