Skip to content

Commit 29e97c2

Browse files
auvipyCopilot
andauthored
Update djcelery/schedulers.py
Co-authored-by: Copilot <[email protected]>
1 parent 567a7b7 commit 29e97c2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

djcelery/schedulers.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,27 @@ def from_entry(cls, name, skip_fields=('relative', 'options'), **entry):
141141
expires = options.get('expires')
142142
if expires and not obj.expires:
143143
# if expires is not properly recognized from options
144-
# delete django DateTimeField from the model instance
145-
# and use just simple int as attribute for this call
146-
del obj.expires
147-
obj.expires = expires
144+
# Use a helper function to handle the deletion and reassignment
145+
# of the `expires` field. This ensures clarity and maintainability.
146+
self._handle_expires_field(obj, expires)
148147
return cls(obj)
149148

149+
@staticmethod
150+
def _handle_expires_field(obj, expires):
151+
"""
152+
Safely handle the deletion and reassignment of the `expires` field.
153+
154+
This is necessary because the `expires` field might not be properly
155+
recognized from options, and we need to reset it as a simple attribute.
156+
157+
Args:
158+
obj: The model instance (PeriodicTask).
159+
expires: The new value to assign to the `expires` field.
160+
"""
161+
# Delete the `expires` field from the model instance
162+
del obj.expires
163+
# Reassign the `expires` attribute with the provided value
164+
obj.expires = expires
150165
def __repr__(self):
151166
return '<ModelEntry: {0} {1}(*{2}, **{3}) {4}>'.format(
152167
safe_str(self.name), self.task, safe_repr(self.args),

0 commit comments

Comments
 (0)