Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions press/press/doctype/press_job/jobs/create_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def create_volume_from_snapshot(self):
return

max_retries = self.arguments_dict.get("max_volume_creation_retries", 6)
if self.kv.get("volume_creation_attempts", 0) >= max_retries:
if (self.kv.get("volume_creation_attempts") or 0) >= max_retries:
raise Exception(f"Failed to create volume from snapshot after {max_retries} retries")

is_created = self.virtual_machine_doc.create_data_disk_volume_from_snapshot()
if is_created:
return

self.kv.set("volume_creation_attempts", self.kv.get("volume_creation_attempts", 0) + 1)
self.kv.set("volume_creation_attempts", self.kv.get("volume_creation_attempts") or 0 + 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Operator precedence bug: + binds tighter than or, so this line evaluates as self.kv.get(...) or (0 + 1) — i.e. self.kv.get(...) or 1. After the first attempt stores 1, every subsequent call hits 1 or 1 → 1 and the counter is permanently stuck at 1. The >= max_retries guard (default 6) will therefore never fire after the first retry, leaving the job retrying indefinitely.

Suggested change
self.kv.set("volume_creation_attempts", self.kv.get("volume_creation_attempts") or 0 + 1)
self.kv.set("volume_creation_attempts", (self.kv.get("volume_creation_attempts") or 0) + 1)
Prompt To Fix With AI
This is a comment left during a code review.
Path: press/press/doctype/press_job/jobs/create_server.py
Line: 128

Comment:
Operator precedence bug: `+` binds tighter than `or`, so this line evaluates as `self.kv.get(...) or (0 + 1)` — i.e. `self.kv.get(...) or 1`. After the first attempt stores `1`, every subsequent call hits `1 or 1 → 1` and the counter is permanently stuck at `1`. The `>= max_retries` guard (default 6) will therefore never fire after the first retry, leaving the job retrying indefinitely.

```suggestion
		self.kv.set("volume_creation_attempts", (self.kv.get("volume_creation_attempts") or 0) + 1)
```

How can I resolve this? If you propose a fix, please make it concise.

self.defer_current_task()

@task
Expand Down
Loading