-
Notifications
You must be signed in to change notification settings - Fork 10.3k
fix(postgres): use LIMIT/OFFSET in item_query #51557
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
📝 WalkthroughWalkthroughThe change updates the SQL pagination in Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
erpnext/controllers/queries.py (1)
260-260: Correct fix for PostgreSQL compatibility!The change from MySQL-specific
LIMIT offset, countsyntax to the standard SQLLIMIT count OFFSET offsetsyntax correctly addresses the PostgreSQL error while maintaining compatibility with MySQL/MariaDB.Optional: align style with the rest of the file
For consistency with other pagination clauses in this file (lines 59, 116, 152, 295), consider using lowercase
offsetand removing the trailing space:- limit %(page_len)s OFFSET %(start)s """.format( + limit %(page_len)s offset %(start)s""".format(This is purely a style suggestion and does not affect functionality.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
erpnext/controllers/queries.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-16T05:33:58.723Z
Learnt from: Abdeali099
Repo: frappe/erpnext PR: 51078
File: erpnext/accounts/doctype/financial_report_template/financial_report_engine.py:486-491
Timestamp: 2025-12-16T05:33:58.723Z
Learning: In ERPNext/Frappe codebase, query.run(as_dict=True) returns frappe._dict objects that support both dict-style access (obj["key"]) and attribute-style access (obj.key). Therefore, attribute access on query results is valid and will not raise AttributeError. When reviewing Python code, prefer attribute access (obj.key) for readability where the key is known to exist, but ensure existence checks or fallback handling if there is any doubt about missing keys.
Applied to files:
erpnext/controllers/queries.py
⏰ 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). (1)
- GitHub Check: Summary
|
@mergify rebase |
✅ Branch has been successfully rebased |
82f323f to
2f3bf18
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #51557 +/- ##
========================================
Coverage 79.22% 79.22%
========================================
Files 1167 1167
Lines 122103 122103
========================================
+ Hits 96740 96741 +1
+ Misses 25363 25362 -1
🚀 New features to boost your workflow:
|
Query requires more changes |
Summary
Fix Postgres crash in
erpnext.controllers.queries.item_querycaused by MySQL-style pagination (LIMIT start, page_len).Problem
On Postgres, link-field search for Items (e.g. Sales Invoice → Item field autocomplete) can fail with:
Root cause:
item_queryusesLIMIT %(start)s, %(page_len)swhich is valid in MariaDB/MySQL but invalid in Postgres.Fix
Switch pagination in
item_queryto the portable form:LIMIT %(start)s, %(page_len)sLIMIT %(page_len)s OFFSET %(start)sThis syntax is supported by both Postgres and MariaDB/MySQL.
Why this change
erpnext/controllers/queries.pyTests
pre-commit run --all-files✅Notes
No business logic changes; server-side query only.