-
Notifications
You must be signed in to change notification settings - Fork 9.9k
fix: prevent Background Job Failure When Submitting Unsaved Journal Entry and Stock Reconciliation with More Than 100 rows #50100
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
base: develop
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughTwo submit methods were modified to call self.save() before enqueueing background processing when the workload threshold is exceeded. In erpnext/accounts/doctype/journal_entry/journal_entry.py, JournalEntry.submit now calls self.save() before enqueueing if there are more than 100 accounts. In erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py, StockReconciliation.submit now calls self.save() before enqueueing if there are more than 100 items. Enqueue behavior, messaging, and other control paths remain unchanged. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request has been automatically marked as inactive because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing. |
…-it-to-background-job
…-it-to-background-job
…-it-to-background-job
…-it-to-background-job
…-it-to-background-job
|
Hi @diptanilsaha |
|
Can you explain the use case? |
|
in the following code if data is bigger that 100 the submit will fail. journal_entry = frappe.new_doc("Journal Entry")
journal_entry.set("accounts", [data])
journal_entry.submit()in the following code if data is bigger that 100 the submit will not fail but the journal_entry = frappe.new_doc("Journal Entry")
journal_entry.set("accounts", [data])
journal_entry.save()
journal_entry.is_system_generated = 1
journal_entry.submit()the same will apply on Stock Reconciliation DocType. |
|
Thanks @AmalSharqIT. |
…-it-to-background-job
When creating a
Journal EntryorStock Reconciliationthat contains more than 100 rows and submitting it before saving, ERPNext automatically enqueues the submission process as aBackground Job.However, if the document has not yet been saved, the
Background Jobfails with aDoesNotExistErrorbecause the system cannot find the correspondingJournal Entryrecord in thedatabase.In another scenario, if the document is saved but modified before submission,
Background Jobwill submit the old document, not the new, modified version.The
Background Jobattempts to load the document using:doc = frappe.get_doc(__doctype, __name)However, when submission is enqueued as a
Background Job, the document must exist in the database before the job starts.Otherwise, the queued task cannot find it and fails.
Note: The _submit() method itself calls
self.save()after setting the document status to SubmittedClick to view full error traceback
Traceback (most recent call last): File "/workspace/development/frappe-bench/env/lib/python3.11/site-packages/rq/worker.py", line 1428, in perform_job rv = job.perform() ^^^^^^^^^^^^^ File "/workspace/development/frappe-bench/env/lib/python3.11/site-packages/rq/job.py", line 1278, in perform self._result = self._execute() ^^^^^^^^^^^^^^^ File "/workspace/development/frappe-bench/env/lib/python3.11/site-packages/rq/job.py", line 1315, in _execute result = self.func(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/development/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 225, in execute_job retval = method(**kwargs) ^^^^^^^^^^^^^^^^ File "/workspace/development/frappe-bench/apps/frappe/frappe/model/document.py", line 1711, in execute_action doc = frappe.get_doc(__doctype, __name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/development/frappe-bench/apps/frappe/frappe/__init__.py", line 1308, in get_doc return frappe.model.document.get_doc(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/development/frappe-bench/apps/frappe/frappe/model/document.py", line 85, in get_doc return controller(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/workspace/development/frappe-bench/apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py", line 114, in __init__ super().__init__(*args, **kwargs) File "/workspace/development/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 101, in __init__ super().__init__(*args, **kwargs) File "/workspace/development/frappe-bench/apps/frappe/frappe/model/document.py", line 126, in __init__ self.load_from_db() File "/workspace/development/frappe-bench/apps/frappe/frappe/model/document.py", line 179, in load_from_db frappe.throw( File "/workspace/development/frappe-bench/apps/frappe/frappe/__init__.py", line 609, in throw msgprint( File "/workspace/development/frappe-bench/apps/frappe/frappe/__init__.py", line 574, in msgprint _raise_exception() File "/workspace/development/frappe-bench/apps/frappe/frappe/__init__.py", line 525, in _raise_exception raise exc frappe.exceptions.DoesNotExistError: Journal Entry None not foundbackport version-15-hotfix