Skip to content

fix: PostgreSQL compatibility — explicit boolean comparisons - #2547

Open
skanderphilipp wants to merge 2 commits into
frappe:developfrom
skanderphilipp:develop
Open

fix: PostgreSQL compatibility — explicit boolean comparisons#2547
skanderphilipp wants to merge 2 commits into
frappe:developfrom
skanderphilipp:develop

Conversation

@skanderphilipp

Copy link
Copy Markdown

Fix two PostgreSQL errors found during Frappe v17 (develop) setup:

1. crm_service_level_agreement/utils.py — bare smallint in WHERE

SLA.enabled is a Check field stored as smallint. The query builder generated WHERE enabled without a comparison operator. MariaDB silently coerces smallint → boolean, but PostgreSQL requires explicit comparison.

Fix: .where(SLA.enabled).where(SLA.enabled == 1)

2. crm_notification/crm_notification.py — unknown column in filter

The values dict contained a "doctype" key intended for frappe.get_doc() routing, but the same dict was passed to frappe.db.exists() which interprets all keys as WHERE filter columns. Since tabCRM Notification has no doctype column, PostgreSQL errors.

Fix: Strip the doctype key before passing to frappe.db.exists().


Both fixes are backwards-compatible with MariaDB and follow the existing Frappe query builder patterns.

Fix two PostgreSQL errors:

1. crm_service_level_agreement/utils.py: SLA.enabled is a smallint
   (Check field). PostgreSQL requires explicit comparison in WHERE
   clauses; MariaDB silently coerces smallint to boolean. Changed
   .where(SLA.enabled) to .where(SLA.enabled == 1).

2. crm_notification/crm_notification.py: the values dict passed to
   frappe.db.exists() contained a 'doctype' key that does not
   correspond to a column in tabCRM Notification. PostgreSQL
   rejects unknown columns in WHERE clauses, while MariaDB's
   behavior depends on sql_mode. Stripped the key before the
   existence check.

Both fixes are backwards-compatible with MariaDB.
@mergify

mergify Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "fix: PostgreSQL — demo data case sensiti..." | Re-trigger Greptile

Two fixes for v17/develop with PostgreSQL backend:

1. Demo data used 'Budget constraints' but the actual Lost Reason
   record is named 'Budget Constraints' (uppercase C). PostgreSQL
   string comparison is case-sensitive by default, while MariaDB
   uses case-insensitive collation. Fixed to match exact record name.

2. CRM Lost Reasons are required by demo data but were only defined
   in test_records.json (loaded during tests). Added them as app
   fixtures so they are created during bench install-app crm,
   ensuring demo data works on fresh installations.

Both fixes are backwards-compatible with MariaDB.
@codecov-commenter

codecov-commenter commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.47%. Comparing base (b912542) to head (fb5e866).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2547   +/-   ##
========================================
  Coverage    67.46%   67.47%           
========================================
  Files          173      173           
  Lines        11620    11622    +2     
========================================
+ Hits          7840     7842    +2     
  Misses        3780     3780           
Files with missing lines Coverage Δ
crm/demo/deals.py 98.71% <ø> (ø)
.../fcrm/doctype/crm_notification/crm_notification.py 56.66% <100.00%> (+1.49%) ⬆️
.../fcrm/doctype/crm_service_level_agreement/utils.py 78.57% <ø> (ø)
crm/hooks.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants