Bogdanp/dramatiq

Differences in "message_id" [redis as broker] and hand presets "message_id"

RemiZOffAlex opened this issue · 1 comments

What OS are you using?

Fedora 39

What version of Dramatiq are you using?

dramatiq==1.16.0

What did you do?

worker.py

import dramatiq

@dramatiq.actor
def task():
    pass

@dramatiq.actor
def print_result(message_data, result):
    pass

@dramatiq.actor
def print_error(message_data, exception_data):
    pass

In REPL

from worker import *
import uuid

job = task.send()
message_id = str(uuid.uuid4())
job = task.send_with_options(
    args=(),
    message_id=message_id,
    on_failure=print_error,
    on_success=print_result,
)
message_id
job
job.message_id
job.options['message_id']
assert message_id == job.message_id

What did you expect would happen?

>>> assert 1==1
>>>

What happened?

Output

>>> message_id
'fea484fc-21a6-42a6-9764-196a7b7e8999'
>>> job
Message(queue_name='default', actor_name='task', args=(), kwargs={}, options={'message_id': 'fea484fc-21a6-42a6-9764-196a7b7e8999', 'on_failure': 'print_error', 'on_success': 'print_result', 'redis_message_id': '772228c3-3b9e-4ae7-ae60-bbe834a378d1'}, message_id='12580666-4fa1-4206-87e3-1883b371c417', message_timestamp=1713582405679)
>>> job.message_id
'12580666-4fa1-4206-87e3-1883b371c417'
>>> job.options['message_id']
'fea484fc-21a6-42a6-9764-196a7b7e8999'
>>> assert message_id == job.message_id
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

This is working as intended. You're setting an option called message_id on the message, not its id field. If you want to control message ids, you'll have to construct a Message manually and enqueue that directly with your broker.