Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
7 tasks done
davidshepherd7 opened this issue Sep 9, 2024 · 0 comments
Open
7 tasks done

Comments

@davidshepherd7
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant