Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
`before_rename` Hook Fires Twice When Rename Is Enqueued | GoodFirstPicks

`before_rename` Hook Fires Twice When Rename Is Enqueued

frappe/frappe 0 comments 13d ago
View on GitHub
lowopenScope: clearSkill match: yesTest focusedFrappe / ERPNextPython

Why this is a good first issue

The issue involves a clear bug with a straightforward fix and testable behavior.

AI Summary

The `before_rename` hook fires twice when a rename operation is enqueued, causing side effects to execute multiple times. The fix involves skipping validation in the background job since it already ran synchronously before queuing. The issue is well-documented and testable.

Issue Description

Description of the issue

When update_document_title is called with enqueue=True and the scheduler is active, the before_rename controller hook is called twice:

  1. Once inside update_document_title itself — to get the transformed name for pre-validation before queuing
  2. Again inside rename_doc when the background job executes — because rename_doc calls old_doc.run_method("before_rename", ...) with validate=True (the default)

Any before_rename implementation with side effects — sending emails, writing to external services, updating related records — will execute twice.

Context information (for bug reports)

Output of bench version

frappe 15.x.x (or develop branch)

Steps to reproduce the issue

  1. Create a DocType with a custom before_rename hook that has a visible side effect (e.g. creates a log entry, sends an email, increments a counter)
  2. Call update_document_title with enqueue=True on a document of that DocType
  3. Wait for the background job to complete
  4. Check how many times the side effect occurred

Observed result

before_rename side effect occurs twice — once immediately and once after the background job completes.

Expected result

before_rename should fire exactly once per rename operation.

Stacktrace / full error message

No exception — this is a silent double-execution bug.

Additional information

Call chain when enqueue=True:

update_document_title
  └── doc.run_method("before_rename", ...)        ← 1st call
  └── validate_rename(..., save_point=True)
  └── doc.queue_action("rename", ...)
        └── [background] execute_action
              └── doc.rename()
                    └── rename_doc(validate=True)
                          └── old_doc.run_method("before_rename", ...)  ← 2nd call

Fix — skip validation (and therefore before_rename) in the background job since it already ran synchronously before queuing:

# In update_docu

GitHub Labels

bug

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • potential side effects
Loading labels...

Details

Points10 pts
Difficultylow
Scopeclear
Skill Matchyes
Test Focusedyes