Skip to content

Non-optimal select in _dramatiq_task_runner #116

@amureki

Description

@amureki

Greetings!

I am not 100% sure if this is intended behaviour, so I am creating an issue to clarify that.

task = Task.objects.select_for_update().get(pk=task_pk, completed=None)
workflow = (
task.content_type.model_class()
.objects.select_for_update(nowait=True)
.get(pk=workflow_pk)
)
try:
logger.info("Executing %r", task)
node = task.node
with_task = getattr(node, "with_task", False)
kwargs = {}
if with_task:
kwargs["task"] = task
with with_reversion(task):
result = node(workflow, **kwargs)
except OperationalError:
raise

Here, we are executing queries (because we are calling .get(), so it is not lazy) outside try-catch which I guess is supposed to log and catch it.
So I get a feeling that try-catch here is not actually doing anything.

If you agree, I am happy to provide a patch to either drop this try-catch (since we are raising OperationalError anyways) or we move the queries inside it.

Best,
Rust

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions