TypeError: '_SentinelObject' object is not callable
I am upgrading my Django application from version 2.2 to 3.2. while upgrading i am facing below issue, i have spent a lot of time to resolve this but didn't get any solution yet.
here's the traceback of issue which i am facing:
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
Any help would be highly appreciated.
Thanks in advance.
Solution 1:
Assigning objects which don't support copy.deepcopy()
during setUpTestData()
is deprecated. Either assign the unit attribute during setUpClass()
or setUp()
, or add support for deepcopy()
.
So there might be a code in your test cases like below:
@classmethod
def setUpTestData(cls):
super(YourTestClassNameHere, cls).setUpTestData()
Change this code as follows:
@classmethod
def setUpClass(cls):
super(YourTestClassNameHere, cls).setUpClass()
This will resolve your _SentinelObject
issues.