Skip to content

[FIX] stock_account: skip accounts that don't exist yet in company_data - #5887

Closed
quoc-pn wants to merge 1 commit into
OCA:19.0from
komit-consulting:19.0-fix-stock_account-empty-company-data
Closed

[FIX] stock_account: skip accounts that don't exist yet in company_data#5887
quoc-pn wants to merge 1 commit into
OCA:19.0from
komit-consulting:19.0-fix-stock_account-empty-company-data

Conversation

@quoc-pn

@quoc-pn quoc-pn commented Aug 5, 2026

Copy link
Copy Markdown
Member

Bug

Follow-up to #5885, which fixed the case where a record already exists but the target field is already set. There is still a related bug for records that don't exist yet.

update_from_coa_generic() in stock_account/19.0.1.1/end-migration.py builds filtered_records[record_id] based on whether the target field appears unset via not ref_or_id(record_id, model_name)[key]. When ref_or_id() can't resolve the xmlid to an existing account.account (the account hasn't been created yet in this company's chart), indexing [key] on the resulting empty recordset is also falsy — so a not-yet-existing account is treated the same as an existing account with the field unset.

AccountChartTemplate._load_data(company_data) then creates a new account.account row from only the partial company_data (just the 2 stock-account fields), missing required fields like name/account_type, causing:

null value in column "name" of relation "account_account" violates not-null constraint

Fix

Skip record_ids that don't resolve to an existing record instead of partially-creating them. This script is meant to backfill fields on existing accounts, not create new ones.

Test

Reproduced during a 19.0 migration where stock_account's end-migration.py crashed on AccountChartTemplate._load_data() with the above error even after #5885; confirmed the crash disappears with this fix applied.

update_from_coa_generic() included a record_id in filtered_records
whenever the target field appeared unset. But when ref_or_id() can't
resolve the xmlid to an existing account.account record, indexing the
field on the resulting empty recordset is also falsy, so a
not-yet-existing account was treated the same as an existing account
with the field unset.

AccountChartTemplate._load_data() then created a new account.account
row from only the partial company_data (the 2 stock-account fields),
missing required fields like name/account_type, causing:

  null value in column "name" of relation "account_account"
  violates not-null constraint

Skip record_ids that don't resolve to an existing record instead of
partially-creating them.
@OCA-git-bot OCA-git-bot added mod:openupgrade_scripts Module openupgrade_scripts series:19.0 labels Aug 5, 2026
@legalsylvain
legalsylvain marked this pull request as draft August 5, 2026 11:59
@MiquelRForgeFlow MiquelRForgeFlow added this to the 19.0 milestone Aug 5, 2026
@MiquelRForgeFlow
MiquelRForgeFlow requested a review from hbrunn August 5, 2026 15:11
@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

Conflicts.

@quoc-pn quoc-pn closed this Aug 6, 2026
@quoc-pn
quoc-pn deleted the 19.0-fix-stock_account-empty-company-data branch August 6, 2026 02:48
@quoc-pn
quoc-pn restored the 19.0-fix-stock_account-empty-company-data branch August 6, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:openupgrade_scripts Module openupgrade_scripts series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants