[FIX] stock_account: avoid creating blank account.account records - #5885
Merged
MiquelRForgeFlow merged 1 commit intoAug 5, 2026
Merged
Conversation
update_from_coa_generic() decided whether to include a record in company_data based on the raw chart template data (outer `any()` check), but the actual values loaded were filtered separately based on whether the existing account already had the field set. When an account already had account_stock_expense_id/account_stock_variation_id set, the per-record dict ended up empty while the record was still included in company_data. _load_data() then created a brand new account.account from that empty vals dict (since the xmlid did not resolve to an existing record yet), producing a row with only ORM defaults and no name, which violates the NOT NULL constraint on account_account.name. Only include a record in company_data when it actually has filtered values to load.
Contributor
|
Thanks @quoc-pn. BTW, why PR is in draft? |
quoc-pn
marked this pull request as ready for review
August 5, 2026 11:02
Member
Author
@MiquelRForgeFlow Thanks for your review. I marked the PR as ready. |
hbrunn
reviewed
Aug 5, 2026
| if key in field_names and not ref_or_id(record_id, model_name)[key] | ||
| } | ||
| for record_id, record_data in template_data[model_name].items() | ||
| if any(record_data.get(key) for key in field_names) |
Member
There was a problem hiding this comment.
why is this check removed? It avoids crashes for COAs that don't define the field in question.
And obviously generated PRs need to conform https://github.com/OCA/.github/blob/master/AI_POLICY.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
update_from_coa_generic()instock_account/19.0.1.1/end-migration.pydecided whether to include a record incompany_databased on the raw chart template data (the outerany(record_data.get(key) for key in field_names)check), while the actual values to load were filtered separately based on whether the existing account already had the field set (not ref_or_id(record_id, model_name)[key]).When an account already had
account_stock_expense_id/account_stock_variation_idset on the existing record, the inner per-record dict ended up empty ({}) — but the record was still included incompany_databecause the outer check only looked at the raw template data.AccountChartTemplate._load_data(company_data)then tried to load that empty vals dict. Since the xmlid didn't yet resolve to an existing record, it was treated as "to create", producing a newaccount.accountrow with only ORM defaults (noname,account_type, etc.), which crashes with:Fix
Only include a record in
company_datawhen the filtered per-record dict is actually non-empty, instead of relying on a separate check against the raw template data.Test
Reproduced during a 19.0 migration where
stock_account'send-migration.pycrashed onAccountChartTemplate._load_data()with the above error; confirmed the crash disappears with this fix applied.