2

First I chain tasks like this

tasks_chain = chain(create_game_folder.si(instance.id))
tasks_chain |= download_game.si(instance.id).set(
            task_id=str(task_id)
        )

But I get this error

    logger.debug(f"{game_id=}")
AttributeError: 'UUID' object has no attribute 'game_id'

This is how the create folder function starts


@shared_task()
def create_game_folder(game_id):
    logger.info("create_game_folder")
    logger.debug(f"{game_id=}")
    game = Game.objects.get(id=game_id)

Why is it trying to get game_id from UUID? I know that instance.id returns a UUID object but if I do str(instance.id) I get AttributeError: 'str' object has no attribute 'game_id'

Is this something .si() or .delay() do in the background and for some reason the stacktrace is showing me the logger line?

Update:

/etc/systemd/system/celery.service

[Unit]
Description=Celery Service
Requires=django-app.service
After=django-app.service

[Service]
Type=forking
User=david
Group=vboxsf
RuntimeDirectory=celery
WorkingDirectory=/var/www/html/django-app.com
ExecStart=poetry run celery -A game_manager multi start worker --loglevel="INFO" --concurrency=5
ExecStop=poetry run celery multi stopwait worker --loglevel="INFO"
ExecReload=poetry run celery -A game_manager multi restart worker --loglevel="INFO" --concurrency=5
Restart=always

[Install]
WantedBy=multi-user.target

celery config

# Celery configuration
CELERY_BROKER_URL = "redis://localhost:6379"
CELERY_RESULT_BACKEND = "redis://localhost:6379"
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'UTC'
CELERY_ENABLE_UTC = True

/etc/systemd/system/django-app.service

[Unit]
Description=Start Django app
After=network.target

[Service]
User=david
Group=david
Environment="PYTHONUNBUFFERED=TRUE"
WorkingDirectory=/var/www/html/django-app.com
ExecStart=poetry run gunicorn game_manager.wsgi:application --config game_manager/gunicorn_conf.py --reload

[Install]
WantedBy=multi-user.target
7
  • When the error is raised? When a task is executed by worker or when you build the task signature? If this error is raised during development could you restart the worker in order to have updated code in worker too? Commented Jul 12, 2023 at 7:03
  • In the worker during development, I'm pretty sure I've done systemctl restart celery multiple times and still got the error, now I've done it again and it seems to have ACTUALLY updated the code. Added services files in OP just in case I have something wrong there. Commented Jul 12, 2023 at 7:23
  • Could you extend the stack trace when AttributeError: 'UUID' object has no attribute 'game_id' occurs, please? Commented Jul 12, 2023 at 7:50
  • Also, it would be good to know what happens to tasks_chain later. Do you call delay? Commented Jul 12, 2023 at 7:51
  • The stacktrace sometimes showed one line as being the problem and sometimes a different one (that apparently had no relation to the error), you were probably right about the worker not having updated code, I could have sworn I had restarted the service multiple times with no luck, so I have no idea why after restarting today again it fixed itself. Yes I did tasks_chain.delay() now changed to transaction.on_commit(lambda: tasks_chain.delay()) due to ATOMIC_REQUESTS being true. Commented Jul 12, 2023 at 8:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.