Skip to content

Commit c2590fb

Browse files
committed
[FIX] util/records: avoid row-based IS NOT NULL
While using row-based `IS {,NOT} NULL`, especially after doing LEFT JOIN we need to be very carefull as: 1. IS NULL = true if the `row is NULL OR all columns are NULL`[^1] 2. IS NOT NULL = true if the `row is NOT NULL AND all columns are NOT NULL`[^1] So for making it safe, we used `t2.<column> IS NOT NULL` instead of `t2 IS NOT NULL` when the <column> was used while joining ref: odoo/upgrade#8957 [^1]: https://www.postgresql.org/docs/12/functions-comparison.html closes #361 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 6fbf957 commit c2590fb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/util/records.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,11 +1744,12 @@ def replace_record_references_batch(
17441744
-- there is no target already present within the same constraint
17451745
NOT EXISTS(SELECT 1 FROM {table} WHERE {res_model_whr} AND {jmap_expr} AND {where_clause})
17461746
-- there is no other entry with the same target within the same constraint
1747-
AND NOT (t2 IS NOT NULL AND {where_clause2})
1747+
AND NOT (t2.{res_id} IS NOT NULL AND {where_clause2})
17481748
""",
17491749
table=ir.table,
17501750
res_model_whr=res_model_whr,
17511751
jmap_expr=jmap_expr,
1752+
res_id=ir.res_id,
17521753
where_clause=SQLStr(" AND ".join(format_query(cr, "{0}=t.{0}", col) for col in uniq_cols))
17531754
if uniq_cols
17541755
else SQLStr("True"),

0 commit comments

Comments
 (0)