My Redis Url pointing still connecting to local host instead or railway
mchenro
FREEOP

2 months ago

The logs show a classic "silent failure" in configuration. Your settings.py is correctly fetching the Railway URL (the DEBUG print proves that), but the Celery App is not successfully pulling that value from the Django settings object, causing it to fall back to its internal default (localhost).

$10 Bounty

2 Replies

aymenkani
FREE

2 months ago

Here is what is almost certainly happening: Celery is ignoring your variable because it’s wearing "blinders."

In your celery.py file, you probably have a line that looks like this: app.config_from_object('django.conf:settings', namespace='CELERY')

That namespace='CELERY' part is the culprit. It tells Celery, "Only pay attention to variables that start with CELERY_."

So, even though your REDIS_URL is correct (which is why your print statement works), Celery scans your settings, doesn't see anything starting with CELERY_BROKER_URL, shrugs, and defaults back to localhost.

Here is the quick fix:

Go into your settings.py and make sure you are explicitly defining the broker with that prefix. Just add this:

Python

CELERY_BROKER_URL = os.environ.get('REDIS_URL')

If you already have that, double-check that you aren't accidentally overwriting it later in the file.

Give that a try and tell me if it does fix the connection?


aymenkani

Here is what is almost certainly happening: Celery is ignoring your variable because it’s wearing "blinders."In your celery.py file, you probably have a line that looks like this: app.config_from_object('django.conf:settings', namespace='CELERY')That namespace='CELERY' part is the culprit. It tells Celery, "Only pay attention to variables that start with CELERY_."So, even though your REDIS_URL is correct (which is why your print statement works), Celery scans your settings, doesn't see anything starting with CELERY_BROKER_URL, shrugs, and defaults back to localhost.Here is the quick fix:Go into your settings.py and make sure you are explicitly defining the broker with that prefix. Just add this:PythonCELERY_BROKER_URL = os.environ.get('REDIS_URL')If you already have that, double-check that you aren't accidentally overwriting it later in the file.Give that a try and tell me if it does fix the connection?

mchenro
FREEOP

2 months ago

I had already done this earlier, but the issue still persisted. Based on your comment “If you already have that, double-check that you aren’t accidentally overwriting it later in the file”. I reviewed my configuration again and noticed that I had previously set CELERY_BROKER_URL and CELERY_RESULT_BACKEND to redis://127.0.0.1:6379/0 in the Railway environment variables for both the web and worker services at an earlier stage of the project. I believe this was overriding the correct Redis configuration and is the root cause of the issue. Thanks anyways.

On both Web and Worker services, i did the following below and it worked.:

REMOVE

  • CELERY_BROKER_URL

  • CELERY_RESULT_BACKEND

KEEP ONLY

  • REDIS_URL


Loading...