Skip to content

local variable group_completion referenced before assignment #300

Description

@thomas-dufour

Issues

Got error local variable 'group_completion' referenced before assignment in case of constant fail despite retries.

Version

remoulade version: remoulade[rabbitmq,redis]==0.48.0

traceback

Traceback (most recent call last):
  File "/home/unprivileged/.local/lib/python3.8/site-packages/remoulade/broker.py", line 168, in emit_after
    getattr(middleware, "after_" + signal)(self, *args, **kwargs)
  File "/home/unprivileged/.local/lib/python3.8/site-packages/remoulade/middleware/pipelines.py", line 58, in after_process_message
    if group_info and not self._group_completed(message, group_info, broker):
  File "/home/unprivileged/.local/lib/python3.8/site-packages/remoulade/middleware/pipelines.py", line 129, in _group_completed
    group_competed = group_completion >= group_info.children_count
UnboundLocalError: local variable 'group_completion' referenced before assignment

Understanding

During a pipeline that failed for every retries, the context manager remoulade.results.backend.py:ResultBackend.retry catch the error and skip the assigment of variable group_completion. Just after, there is a test on group_completion that can be unassigned.

Proposed fix

adding default assignment of group_completion

/remoulade/middleware/pipelines.py
@@ -123,6 +123,7 @@ class Pipelines(Middleware):
         except NoResultBackend as e:
             raise NoResultBackend("Pipeline with groups are ony supported with a result backend") from e
 
+        group_completion = float("-inf")  # noqa
         with results.backend.retry(broker, message, self.logger):
             ttl = results.get_option("result_ttl", broker=broker, message=message)
             group_completion = results.backend.increment_group_completion(group_info.group_id, message.message_id, ttl)
         group_competed = group_completion >= group_info.children_count

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions