TypeError: '_SentinelObject' object is not callable

TypeError: '_SentinelObject' object is not callable

我正在将我的 Django 应用程序从版本 2.2 升级到 3.2。在升级时我遇到了以下问题,我花了很多时间来解决这个问题但还没有得到任何解决方案。

这是我面临的问题的追溯:

  File ".../abc/test.py", line 85, in setUp
    self.MODEL_A.save()
  File ".../abc/models.py", line 470, in save
    super(MODEL_A, self).save(*args, **kwargs)
  File ".../lib/python3.8/site-packages/django/db/models/base.py", line 726, in save
    self.save_base(using=using, force_insert=force_insert,
  File ".../lib/python3.8/site-packages/django/db/models/base.py", line 763, in save_base
    updated = self._save_table(
  File ".../lib/python3.8/site-packages/django/db/models/base.py", line 842, in _save_table
    values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
  File ".../lib/python3.8/site-packages/django/db/models/base.py", line 842, in <listcomp>
    values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
  File ".../lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1396, in pre_save
    value = timezone.now()
TypeError: '_SentinelObject' object is not callable

非常感谢任何帮助。

提前致谢。

setUpTestData() 期间分配不支持 copy.deepcopy() 的对象已弃用。在 setUpClass()setUp() 期间分配单位属性,或添加对 deepcopy().

的支持

因此您的测试用例中可能有如下代码:

@classmethod
def setUpTestData(cls):
    super(YourTestClassNameHere, cls).setUpTestData()

按如下方式更改此代码:

@classmethod
def setUpClass(cls):
    super(YourTestClassNameHere, cls).setUpClass()

这将解决您的 _SentinelObject 问题。