Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local variable group_completion referenced before assignment #300

Open
thomas-dufour opened this issue Jun 27, 2022 · 0 comments
Open

local variable group_completion referenced before assignment #300

thomas-dufour opened this issue Jun 27, 2022 · 0 comments

Comments

@thomas-dufour
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant