fix: prevent max recursion on supplier scorecard save

on_update() called self.save(), which re-enters on_update() via
run_post_save_methods(), recursing indefinitely when make_all_scorecards()
keeps returning newly created periods. Guard the re-save with an in_rescore
flag so the nested on_update() short-circuits, while still running the full
validate() once to refresh score and standings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mihir Kandoi
2026-07-01 16:15:59 +05:30
parent a2f8063804
commit 31e2d4ac5a

View File

@@ -55,8 +55,12 @@ class SupplierScorecard(Document):
self.update_standing()
def on_update(self):
score = make_all_scorecards(self.name)
if score > 0:
# Guard against recursion: the save() below re-enters on_update().
if self.flags.in_rescore:
return
if make_all_scorecards(self.name) > 0:
# New periods were created; re-save to refresh score and standings.
self.flags.in_rescore = True
self.save()
def validate_standings(self):