schemaeditor effectivedefault shouldn t call callable defaults class mystrstr def callself return self class mycharfieldmodels charfield def getdefaultself return self default field mycharfieldmaxlength1 defaultmystr self assertequalbasedatabaseschemaeditor effectivedefaultfield mystr schemaeditor effective_default shouldn t call callable defaults
from django.db import models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.test import SimpleTestCase


class SchemaEditorTests(SimpleTestCase):
    def test_effective_default_callable(self):
        

        class MyStr(str):
            def __call__(self):
                return self

        class MyCharField(models.CharField):
            def _get_default(self):
                return self.default

        field = MyCharField(max_length=1, default=MyStr)
        self.assertEqual(BaseDatabaseSchemaEditor._effective_default(field), MyStr)