#37126: Make Task and TaskResult comparable
--------------------------------+------------------------------------
Reporter: Johannes Maron | Owner: zky
Type: New feature | Status: assigned
Component: Tasks | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------+------------------------------------
Comment (by zky):
Hi Johannes,
Regarding the sorting implementation, while @dataclass(order=True) is
indeed stupidly simple, I noticed two potential issues.
First, it makes the sorting logic strictly dependent on the physical order
of the class attributes, which could cause regressions if someone
accidentally reorders them in the future.
More importantly, since run_after is typed as datetime | None, using
order=True will crash the queue with a TypeError (comparing NoneType and
datetime) whenever a task scheduled to run immediately (run_after=None) is
compared against a scheduled task.
To prevent the queue from crashing and to make the codebase more
defensive, would it be safer to explicitly implement __lt__ and __eq__? We
can safely handle the None fallback inside __lt__ by comparing tuples like
(self.run_after is not None, self.run_after).
Let me know your thoughts!
--
Ticket URL: <https://code.djangoproject.com/ticket/37126#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019e7cbbfb90-289cefcf-122a-4c4a-9675-329ec13ee67f-000000%40eu-central-1.amazonses.com.