Skip to content

[OU-FIX] payment: fill payment.method.provider_id from the old relation - #16

Merged
cursor[bot] merged 4 commits into
20.0from
cursor/ou-20-08c-payment-method-provider-3e8f
Nov 12, 2026
Merged

cursor[bot] merged 4 commits into
20.0from
cursor/ou-20-08c-payment-method-provider-3e8f

Conversation

@adekock11

@adekock11 adekock11 commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Symptom

Two failures while upgrading payment to 20.0:

psycopg2.errors.UndefinedColumn: column "code" does not exist

from _deduplicate_provider_code, and after that query is removed:

Missing not-null constraint on payment.method.provider_id

A server retest then left 8 catalog methods NULL: Discover, JCB, Codensa, MyBank, PPS, Venmo, V PAY and WeLend. They have no tokens, transactions or provider links. The only rows that point at them are country, currency and image relations, and those foreign keys are ON DELETE CASCADE.

Root cause

_deduplicate_provider_code asked information_schema for SELECT code IS NOT NULL. code is not a column of information_schema.columns. The probe raises before any dedupe runs.

provider_id is required in 20.0. In 19.0 a method is one shared row linked to providers through payment_method_payment_provider_rel. In 20.0 each method belongs to one provider. Provider modules create those rows themselves and set provider_id in the data file, for example payment_adyen / payment_method_discover with provider_id = payment.payment_provider_adyen. The core payment module no longer ships those catalog xmlids. The 19.0 rows are noupdate leftovers with no provider.

_payment_method_fks treated every foreign key as a reference. Cascade and set-null constraints do not block the delete: PostgreSQL drops the linking rows or clears the column. The 8 catalog methods stayed NULL only because those cascade relations existed.

Decision

Delete a payment.method whose provider_id is NULL when no blocking foreign key points at it, and delete its ir.model.data rows with it.

A foreign key blocks the delete only when confdeltype is not c (ON DELETE CASCADE) or n (ON DELETE SET NULL). RESTRICT and NO ACTION still count. primary_payment_method_id still counts. Dedup rewrites every foreign key, including cascade, before it deletes a duplicate (provider_id, code).

That matches 20.0. A method cannot exist without a provider. Dropping these catalog rows loses no transaction, token, or brand link. The cascade relations disappear with the row. When payment_adyen (or whichever provider module) loads later in the same upgrade, its data file creates a new method with provider_id set. If that provider module is not installed, the method should not exist.

If a method is still referenced by a blocking foreign key and no single provider can be chosen for it, it stays NULL and the log says so.

The (provider_id, code) dedupe starts with openupgrade.column_exists(cr, "payment_method", "code") and returns when the column is absent.

Also in this script

  • One method row per provider from payment_method_payment_provider_rel. The lowest provider id keeps the existing row. Further providers get a copy.
  • Transactions and tokens follow the provider they were paid with.
  • Duplicate (provider_id, code) rows keep the lowest id.

Verification

ruff and py_compile are clean. Not merged. The server upgrade is the check for the catalog rows.

Upstream

Generic, for OCA 20.0 on top of OCA#6068.

Open in Web Open in Cursor 

cursoragent and others added 3 commits November 12, 2026 07:03
A method with no provider is kept when it is a primary payment method or
still has an xmlid. The dedupe map is dropped first so a retried run can
recreate it.

Co-authored-by: André de Kock <[email protected]>
column_exists replaces the information_schema probe that selected a
nonexistent column named code. Shared 19.0 catalog methods with an xmlid
and no provider are removed, xmlid included, so provider-module data can
recreate them with provider_id. The warning no longer says those rows were
linked to more than one provider.

Co-authored-by: André de Kock <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 12, 2026
…) into 20.0-integration-2

Co-authored-by: André de Kock <[email protected]>
Country, currency and image relations are ON DELETE CASCADE, so they
kept Discover, JCB and the other provider-less catalog methods from
being deleted. Only RESTRICT and NO ACTION foreign keys count as a
reference. Dedup still rewrites every foreign key.

Co-authored-by: André de Kock <[email protected]>
cursor Bot pushed a commit that referenced this pull request Nov 12, 2026
…) into 20.0-integration-2

Ignore ON DELETE CASCADE and SET NULL foreign keys when dropping
provider-less catalog methods.

Co-authored-by: André de Kock <[email protected]>
@cursor
cursor Bot merged commit 745f075 into 20.0 Nov 12, 2026
4 of 5 checks passed
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