Bogdanp/dramatiq

Message.__lt__ raises if queue, actor name and (non-kw) args are all equal

Opened this issue · 0 comments

Issues

Checklist

  • Does your title concisely summarize the problem?
  • Did you include a minimal, reproducible example?
  • What OS are you using?
  • What version of Dramatiq are you using?
  • What did you do?
  • What did you expect would happen?
  • What happened?

What OS are you using?

Ubuntu 24.04 LTS

What version of Dramatiq are you using?

1.14.2

What did you do?

    a = dramatiq.Message("foo_queue", "foo_actor", (1,), {"x": 1}, {})
    b = dramatiq.Message("foo_queue", "foo_actor", (1,), {"x": 1}, {})
    a < b

What did you expect would happen?

Returns False.

What happened?

The Message.__lt__ operator attempts to compare the two kwargs dicts, which fails because dictionaries are not comparable:

    def __lt__(self, other: "Message") -> bool:
>       return dataclasses.astuple(self) < dataclasses.astuple(other)
E       TypeError: '<' not supported between instances of 'dict' and 'dict'

Other notes

Specifically this came up from pushing (a, b, c, message) with equal (a, b, c) into a PriorityQueue inside a test-only synchronous broker.

But, I think the same issue could happen in dramatiq's production worker code here if a single worker process has multiple messages with the same priority, queue, actor, and args. We haven't ever seen this happen in production, but our configuration would make this extremely unlikely (one worker thread per process, with prefetch of 2).

I'm just reporting this so that you know about it in case you want to do something, no pressure to fix it :) Thanks for building + sharing such a great job system!