Skip to content

fix(press-job): Workflow kv object doesn't support default#6425

Merged
tanmoysrt merged 1 commit into
frappe:masterfrom
tanmoysrt:fix_kv_access_in_job
May 13, 2026
Merged

fix(press-job): Workflow kv object doesn't support default#6425
tanmoysrt merged 1 commit into
frappe:masterfrom
tanmoysrt:fix_kv_access_in_job

Conversation

@tanmoysrt

Copy link
Copy Markdown
Member

(cherry picked from commit 16d1b6c)

@tanmoysrt tanmoysrt requested a review from ssiyad as a code owner May 13, 2026 11:49
@tanmoysrt tanmoysrt merged commit c8d8d2d into frappe:master May 13, 2026
3 of 5 checks passed
@mergify

mergify Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

@tanmoysrt, thanks for the contribution, but we do not accept pull requests on a master. Please close this PR and raise PR on an develop branch.

@frappe-pr-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 0.31.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@greptile-apps

greptile-apps Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes kv.get() calls that were incorrectly passing a second default argument — an argument the KVStoreInterface abstract method does not support — by replacing them with or 0 fallbacks. The fix on line 121 is correct, but the fix on line 128 introduces a Python operator-precedence bug.

  • Line 121 (if (self.kv.get("volume_creation_attempts") or 0) >= max_retries) — correct.
  • Line 128 (self.kv.set(..., self.kv.get("volume_creation_attempts") or 0 + 1)) — broken: + binds before or, so this resolves to get(...) or 1, freezing the counter at 1 after the first retry and preventing the max_retries guard from ever firing again.

Confidence Score: 3/5

The retry counter will get stuck at 1 after the first failed volume-creation attempt, so the max-retries guard never triggers and the job retries indefinitely instead of surfacing a failure.

The partial fix is worse than the original: the first line correctly handles the missing default, but the second line freezes the counter due to an operator-precedence oversight, breaking the entire retry-limiting mechanism for create_volume_from_snapshot.

press/press/doctype/press_job/jobs/create_server.py — line 128 needs the parentheses corrected before merging.

Important Files Changed

Filename Overview
press/press/doctype/press_job/jobs/create_server.py Fixes the kv.get() call that incorrectly passed a default argument the interface doesn't support, but introduces an operator-precedence bug on line 128: or 0 + 1 evaluates as or (0 + 1), freezing the retry counter at 1.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[create_volume_from_snapshot called] --> B{data_disk_snapshot exists?}
    B -- No --> C[return early]
    B -- Yes --> D{snapshot_volume_id already set?}
    D -- Yes --> C
    D -- No --> E[Read volume_creation_attempts from kv]
    E --> F{attempts OR 0 >= max_retries?}
    F -- Yes --> G[raise Exception]
    F -- No --> H[create_data_disk_volume_from_snapshot]
    H --> I{is_created?}
    I -- Yes --> C
    I -- No --> J["kv.set(attempts, (attempts OR 0) + 1)"]
    J --> K[defer_current_task]

    style J fill:#f96,color:#000
    style G fill:#f66,color:#fff
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
press/press/doctype/press_job/jobs/create_server.py:128
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)
```

Reviews (1): Last reviewed commit: "fix(press-job): Workflow kv object doesn..." | Re-trigger Greptile

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.

@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.71%. Comparing base (0db67fe) to head (383bf6e).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #6425       +/-   ##
===========================================
+ Coverage   49.40%   59.71%   +10.31%     
===========================================
  Files         940      110      -830     
  Lines       78104    17348    -60756     
  Branches      355      355               
===========================================
- Hits        38588    10360    -28228     
+ Misses      39493     6965    -32528     
  Partials       23       23               
Flag Coverage Δ
dashboard 59.71% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants