MCPcopy
hub / github.com/django/django / _check_fix_default_value

Method _check_fix_default_value

django/db/models/fields/__init__.py:2624–2644  ·  view source on GitHub ↗

Warn that using an actual date or datetime value is probably wrong; it's only evaluated on server startup.

(self)

Source from the content-addressed store, hash-verified

2622 super().__init__(verbose_name, name, **kwargs)
2623
2624 def _check_fix_default_value(self):
2625 """
2626 Warn that using an actual date or datetime value is probably wrong;
2627 it's only evaluated on server startup.
2628 """
2629 if not self.has_default():
2630 return []
2631
2632 value = self.default
2633 if isinstance(value, datetime.datetime):
2634 now = None
2635 elif isinstance(value, datetime.time):
2636 now = _get_naive_now()
2637 # This will not use the right date in the race condition where now
2638 # is just before the date change and value is just past 0:00.
2639 value = datetime.datetime.combine(now.date(), value)
2640 else:
2641 # No explicit time / datetime value -- no checks necessary
2642 return []
2643 # At this point, value is a datetime object.
2644 return self._check_if_value_fixed(value, now=now)
2645
2646 def deconstruct(self):
2647 name, path, args, kwargs = super().deconstruct()

Callers

nothing calls this directly

Calls 4

_get_naive_nowFunction · 0.85
has_defaultMethod · 0.80
combineMethod · 0.80
_check_if_value_fixedMethod · 0.80

Tested by

no test coverage detected