Bogdanp / django_dramatiq

A Django app that integrates with Dramatiq.
https://dramatiq.io
Other
332 stars 77 forks source link

Error related to periodiq middleware with version 0.11.0 #131

Closed kcleong closed 1 year ago

kcleong commented 1 year ago

I tried upgrading django_dramatiq from version 0.10.0 to 0.11.0 in a working Django + dramatiq + periodiq set-up.

Python 3.10.4 is used, with the following requirements.txt:

Django==4.1.3
git+https://github.com/Sovetnikov/django_periodiq
dramatiq[rabbitmq, watch]==1.13.0
django-dramatiq==0.11.0

Django config:

DRAMATIQ_BROKER = {
    "BROKER": "dramatiq.brokers.rabbitmq.RabbitmqBroker",
    "OPTIONS": {
        "url": DRAMATIQ_BROKER_URL,
    },
    "MIDDLEWARE": [
        "dramatiq.middleware.AgeLimit",
        "dramatiq.middleware.TimeLimit",
        "dramatiq.middleware.Callbacks",
        "dramatiq.middleware.Retries",
        "django_dramatiq.middleware.DbConnectionsMiddleware",
        "django_dramatiq.middleware.AdminMiddleware",
        "periodiq.PeriodiqMiddleware",
    ]
}
DRAMATIQ_TASKS_DATABASE = **"default"

I get the following error ValueError: The following actor options are undefined: periodic. Did you forget to add a middleware to your Broker?. Full stack trace available here: https://gist.github.com/kcleong/aded0ca16dfd56304d3774babf4b8471

If I downgrade django_dramatiq to version 0.10.0 the error disapears.

kcleong commented 1 year ago

From what I could gather from a quick debug is that django_dramatiq.apps.DjangoDramatiqConfig.ready() collects the middleware options defined in DRAMATIQ_BROKER['MIDDLEWARE']. However in django.apps.registry:app_config.import_models() the check is triggered (which raises the error) before the dramatiq middleware can be initialized.

amureki commented 1 year ago

Hey @kcleong ! We possibly fixed this issue in the current master branch. May I ask you to try and see if it works for you? Meanwhile, I will release a new version 0.11.1 containing the fix this week.

Best, Rust

kcleong commented 1 year ago

@amureki thanks for your quick reply. I tried the latest master branch and indeed the error does not occur. :)

amureki commented 1 year ago

@amureki thanks for your quick reply. I tried the latest master branch and indeed the error does not occur. :)

That's great! Thanks for the confirmation! Then indeed I'll release it soon. 👍

amureki commented 1 year ago

@kcleong happy to announce that I released 0.11.1! It contains the mentioned fix and should resolve your issue. If you find that this issue is still appearing, feel free to reopen the issue.

Best, Rust