fix: check all successful EBICS requests#374
Open
barredterra wants to merge 1 commit into
Open
Conversation
Comment on lines
+117
to
125
| existing_requests = frappe.get_all( | ||
| "EBICS Request", | ||
| { | ||
| filters={ | ||
| "ebics_user": ebics_user, | ||
| "order_type": order_type, | ||
| "status": "Successful", | ||
| }, | ||
| ["name", "parameters"], | ||
| as_dict=True, | ||
| fields=["parameters"], | ||
| ) |
There was a problem hiding this comment.
Missing
limit on frappe.get_all() — only the first 20 records are returned by default. For any EBICS user who has been syncing daily for more than ~20 days (or has multiple requests per day), the function will silently stop checking records beyond that cutoff. If the record covering request_date happens to be beyond position 20 in the result set, successful_request_exists returns False and a redundant sync is enqueued. Pass limit=0 to fetch all matching rows.
Suggested change
| existing_requests = frappe.get_all( | |
| "EBICS Request", | |
| { | |
| filters={ | |
| "ebics_user": ebics_user, | |
| "order_type": order_type, | |
| "status": "Successful", | |
| }, | |
| ["name", "parameters"], | |
| as_dict=True, | |
| fields=["parameters"], | |
| ) | |
| existing_requests = frappe.get_all( | |
| "EBICS Request", | |
| filters={ | |
| "ebics_user": ebics_user, | |
| "order_type": order_type, | |
| "status": "Successful", | |
| }, | |
| fields=["parameters"], | |
| limit=0, | |
| ) |
23894a6 to
c032f11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
ruff check banking/klarna_kosma_integration/doctype/banking_settings/banking_settings.py banking/klarna_kosma_integration/doctype/banking_settings/test_banking_settings.pyruff format --check banking/klarna_kosma_integration/doctype/banking_settings/banking_settings.py banking/klarna_kosma_integration/doctype/banking_settings/test_banking_settings.pyPYTHONPATH=<split worktree> bench --site frappe-16 run-tests --module banking.klarna_kosma_integration.doctype.banking_settings.test_banking_settings --test TestBankingSettings.test_successful_request_exists_checks_all_matching_requestsGreptile Summary
This PR fixes
successful_request_existsto iterate over all matching successful EBICS Requests instead of only the first one returned byfrappe.db.get_value, and adds a regression test that covers the ordering-dependent failure case.banking_settings.py: Replacesfrappe.db.get_value(single-row) withfrappe.get_all+ a loop so every matching record is checked before concluding no prior sync coversrequest_date.test_banking_settings.py: Addstest_successful_request_exists_checks_all_matching_requests, which inserts a later-dated record first and confirms the function still finds the earlier-dated one.Confidence Score: 3/5
The fix is directionally correct but leaves a gap: frappe.get_all() caps results at 20 by default, so any installation that has accumulated more than ~20 successful EBICS requests will see the same category of miss the PR was meant to eliminate.
The intent of the change is sound but omitting limit=0 means only the first 20 records are ever examined, reintroducing the original failure mode for production systems running daily syncs for more than a few weeks.
banking/klarna_kosma_integration/doctype/banking_settings/banking_settings.py — the frappe.get_all() call needs limit=0.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[daily_sync_ebics] --> B{successful_request_exists?} B --> C[frappe.get_all EBICS Request\nfilters: ebics_user, order_type, status=Successful\n default limit=20] C --> D{more records?} D -- yes --> E[json.loads parameters] E --> F{start_date <= request_date <= end_date?} F -- yes --> G[return True\nskip sync] F -- no --> D E -- JSONDecodeError --> D D -- no --> H[return False\nenqueue sync]Reviews (1): Last reviewed commit: "fix: check all successful EBICS requests" | Re-trigger Greptile