1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #29505 -- Removed SchemaEditor's calling of callable defaults.

Thanks Eugene Pakhomov for the suggested fix.
This commit is contained in:
Tim Graham
2018-11-17 16:18:54 -05:00
parent 0cf85e6b07
commit e62f6e0968
2 changed files with 25 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
from django.db import connection, models
from django.test import TestCase
class SchemaEditorTests(TestCase):
def test_effective_default_callable(self):
"""SchemaEditor.effective_default() shouldn't call callable defaults."""
class MyStr(str):
def __call__(self):
return self
class MyCharField(models.CharField):
def _get_default(self):
return self.default
def get_db_prep_save(self, default, connection):
return default
field = MyCharField(max_length=1, default=MyStr)
with connection.schema_editor() as editor:
self.assertEqual(editor.effective_default(field), MyStr)