Skip to content

Conversation

@ssiyad
Copy link
Member

@ssiyad ssiyad commented Feb 2, 2026

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to harden SQL execution by replacing f-string SQL interpolation with parameterized queries (and adjusting some conditional SQL filters).

Changes:

  • Convert multiple frappe.db.sql calls from f-strings to parameterized %s/%(name)s queries.
  • Update optional filtering logic in benches_with_available_update to avoid string-built WHERE clauses.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
press/press/doctype/site_update/site_update.py Reworks optional SQL filters for benches with updates (now via IS NULL OR ...).
press/press/doctype/site/erpnext_site.py Changes bench-selection query parameter passing (currently uses frappe.db.escape with placeholders).
press/press/doctype/invoice/invoice.py Parameterizes invoice overlap query to avoid string interpolation.
press/api/partner.py Parameterizes dashboard/lead stats queries to avoid interpolated team name.
press/api/analytics.py Parameterizes Plausible “weekly installs” query to avoid interpolated app name.
press/api/account.py Parameterizes permissions query (currently uses frappe.db.escape with placeholders).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +551 to 555
WHERE user=%s or `group` in %s
GROUP BY `document_name`
""",
(frappe.db.escape(user), frappe.db.escape(groups)),
as_dict=True,
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query now uses %s placeholders but still passes frappe.db.escape(user) / frappe.db.escape(groups) as parameters. escape returns SQL-quoted strings, so the driver will quote them again and the lookup will not match (and IN %s will likely break). Pass the raw user and groups tuple as parameters instead (or use named placeholders with a values dict).

Copilot uses AI. Check for mistakes.
Comment on lines +794 to +795
AND (%(site_bench)s IS NULL OR sb.name = %(site_bench)s)
AND (%(server)s IS NULL OR sb.server = %(server)s)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%(site_bench)s and %(server)s placeholders are always present in the SQL now, but values only includes these keys when site/server are passed. Calling benches_with_available_update() with no args (or only one arg) will raise a missing-parameter error. Ensure values always provides both keys (set to None when not filtering), or revert to conditionally appending the WHERE clauses.

Copilot uses AI. Check for mistakes.
"""
return frappe.db.sql(query, [proxy_servers, release_group], as_dict=True)[0].name
return frappe.db.sql(
query, (frappe.db.escape(proxy_servers), frappe.db.escape(release_group)), as_dict=True
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frappe.db.escape(...) should not be used when passing values via %s placeholders—escape returns a SQL-quoted literal, so the DB driver will quote it again, and IN %s may stop matching (or become invalid). Pass raw values instead (e.g., proxy_servers as a list/tuple and release_group as a string) and let frappe.db.sql/the driver handle escaping.

Suggested change
query, (frappe.db.escape(proxy_servers), frappe.db.escape(release_group)), as_dict=True
query, (tuple(proxy_servers), release_group), as_dict=True

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant