diff --git a/djcelery/schedulers.py b/djcelery/schedulers.py index 29d32b9d..21dc4cf3 100644 --- a/djcelery/schedulers.py +++ b/djcelery/schedulers.py @@ -138,8 +138,30 @@ def from_entry(cls, name, skip_fields=('relative', 'options'), **entry): obj, _ = PeriodicTask._default_manager.update_or_create( name=name, defaults=fields, ) + expires = options.get('expires') + if expires and not obj.expires: + # if expires is not properly recognized from options + # Use a helper function to handle the deletion and reassignment + # of the `expires` field. This ensures clarity and maintainability. + self._handle_expires_field(obj, expires) return cls(obj) + @staticmethod + def _handle_expires_field(obj, expires): + """ + Safely handle the deletion and reassignment of the `expires` field. + + This is necessary because the `expires` field might not be properly + recognized from options, and we need to reset it as a simple attribute. + + Args: + obj: The model instance (PeriodicTask). + expires: The new value to assign to the `expires` field. + """ + # Delete the `expires` field from the model instance + del obj.expires + # Reassign the `expires` attribute with the provided value + obj.expires = expires def __repr__(self): return ''.format( safe_str(self.name), self.task, safe_repr(self.args),