mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 14:41:53 +00:00
ci(postgres): flag division by a possibly-zero divisor in the compat guard (#56363)
Adds the division-by-zero divergence class to the PG-compat review tooling: on a divisor that the data can drive to 0 (e.g. Sum(a)/Sum(b)), MariaDB returns NULL for division by zero while PostgreSQL raises `division by zero` and aborts the query. The portable fix is to wrap the divisor in NullIf(divisor, 0), which yields NULL on both engines (matching MariaDB). - .greptile/config.json: add it to the "would ERROR on PostgreSQL" list. - .github/POSTGRES_COMPATIBILITY.md: document it under §1 (hard breaks). - .github/helper/postgres_compat.py: note it in the docstring as a deliberately-not-statically-checked semantic divergence (data-dependent, like integer-division intent), so it stays a reviewer/Greptile concern. Tooling-only; no source query changes. The instance fix shipped in #56361.
This commit is contained in:
5
.github/POSTGRES_COMPATIBILITY.md
vendored
5
.github/POSTGRES_COMPATIBILITY.md
vendored
@@ -73,6 +73,11 @@ Flag a changed query that uses any of these:
|
||||
MariaDB's `IFNULL` is permissive. The common shape is `IfNull(date_col, 0) != 0 / == 0` as a presence test —
|
||||
replace with `date_col.isnotnull()` / `date_col.isnull()` (identical, and valid on both). Otherwise coalesce
|
||||
to a **same-type** default (`Coalesce(date_col, '1900-01-01')`, `Coalesce(text_col, '')`).
|
||||
- **Division by a possibly-zero divisor** — `Sum(a) / Sum(b)`, `x / col`, etc. where the
|
||||
divisor can be `0`/empty. MariaDB returns `NULL` for division by zero; PostgreSQL raises
|
||||
`division by zero` and aborts the query. Wrap the divisor in `NullIf(divisor, 0)` — that
|
||||
yields `NULL` on both engines, matching MariaDB's value. (Only the *literal* `/ 0` is a parse
|
||||
constant; the trap is a divisor that is an aggregate or column the data can drive to zero.)
|
||||
|
||||
---
|
||||
|
||||
|
||||
4
.github/helper/postgres_compat.py
vendored
4
.github/helper/postgres_compat.py
vendored
@@ -7,8 +7,8 @@ that static analysis can catch reliably with a low false-positive rate.
|
||||
|
||||
It deliberately does NOT try to catch the *semantic* divergences (loose GROUP BY,
|
||||
case-sensitive ==/IN, NULL ordering, ORDER BY ... LIMIT 1 tiebreakers, integer-division
|
||||
intent, savepoint discipline) — those genuinely need the test suite. Run the full suite
|
||||
on a Postgres site for those.
|
||||
intent, division by a possibly-zero divisor, savepoint discipline) — those genuinely need
|
||||
the test suite or a human/Greptile reviewer. Run the full suite on a Postgres site for those.
|
||||
|
||||
Escape hatch: put `# pg-ok` anywhere on the offending statement's line span (e.g. on a
|
||||
`SHOW INDEX` query that lives inside an `if frappe.db.db_type == "mariadb":` branch).
|
||||
|
||||
Reference in New Issue
Block a user