Skip to content

[IMP] util.update_record_from_xml#388

Open
Pirols wants to merge 2 commits intoodoo:masterfrom
odoo-dev:master-update_record_from_xml_unset_missing_fields-pied
Open

[IMP] util.update_record_from_xml#388
Pirols wants to merge 2 commits intoodoo:masterfrom
odoo-dev:master-update_record_from_xml_unset_missing_fields-pied

Conversation

@Pirols
Copy link
Contributor

@Pirols Pirols commented Feb 20, 2026

Sometimes records get a field removed from their XML declaration. This creates a
divergence between new dbs and upgraded ones. The former will be initialised
with NULL/default values, whereas the latter will retain their current one.
This is usually handled in dedicated upgrade scripts with simple queries
un/setting the necessary columns. However, in some cases, these XML changes are
backported/noticed too late and need to be addressed in multiple versions.
That may create the pressure to target future versions, which creates a hidden
coupling between the xml declaration and the query, prone to turn into a bug.
It is one such example1 that inspired this PR.

Here update_record_from_xml is adapted to unset fields missing from the xml
declaration, if passed explicitely via the fields kwarg. This enables us to
leverage the foreward compatibility of update_record_from_xml in the scenario
described above, preventing the associated potential bugs.

Footnotes

  1. https://github.com/odoo/upgrade/pull/9512

@Pirols Pirols requested review from a team and aj-fuentes February 20, 2026 16:11
@robodoo
Copy link
Contributor

robodoo commented Feb 20, 2026

Pull request status dashboard

@Pirols Pirols force-pushed the master-update_record_from_xml_unset_missing_fields-pied branch from 16e826d to c3b03d8 Compare February 20, 2026 16:13
Copy link
Contributor

@aj-fuentes aj-fuentes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think current version is correct. My suggestion is because I find a bit simpler to read "override each field not found in the xml" than keeping a list of fields to find.

That being said what I think could be problematic here are field with defaults. We would always write NULL but maybe that's fine for the use cases we have in mind. Another option may be to pass a dict of default values per field... but that may be too much for current cases... @KangOl ?

Sometimes records get a field removed from their XML declaration. This creates a
divergence between new dbs and upgraded ones. The former will be initialised
with `NULL`/default values, whereas the latter will retain their current one.
This is usually handled in dedicated upgrade scripts with simple queries
un/setting the necessary columns. However, in some cases, these XML changes are
backported/noticed too late and need to be addressed in multiple versions.
That may create the pressure to target future versions, which creates a hidden
coupling between the xml declaration and the query, prone to turn into a bug.
It is one such example[^1] that inspired this PR.

Here `update_record_from_xml` is adapted to unset fields missing from the xml
declaration, if passed explicitely via the `fields` kwarg. This enables us to
leverage the foreward compatibility of `update_record_from_xml` in the scenario
described above, preventing the associated potential bugs.

[^1]: odoo/upgrade#9512
@Pirols Pirols force-pushed the master-update_record_from_xml_unset_missing_fields-pied branch from c3b03d8 to d978d47 Compare February 20, 2026 16:42
@Pirols
Copy link
Contributor Author

Pirols commented Feb 20, 2026

That being said what I think could be problematic here are field with defaults. We would always write NULL but maybe that's fine for the use cases we have in mind. Another option may be to pass a dict of default values per field... but that may be too much for current cases

I have the same concern. Another option would be to only inject the Falsey xml field for non default fields.

@KangOl
Copy link
Contributor

KangOl commented Feb 20, 2026

Simple solution. Great.

@KangOl
Copy link
Contributor

KangOl commented Feb 20, 2026

Another option may be to pass a dict of default values per field... but that may be too much for current cases...

We could get the default value from the ORM directly.

@KangOl
Copy link
Contributor

KangOl commented Feb 24, 2026

Even without the get_defauts part, there are 2 bugs in the current patch, both due to the fact that we can find multiple <record> nodes:

  • when we filter out the fields, we can end up with an empty <record> node. We should then not add it to new_root (can be done with a continue statement)
  • we should only add the missing fields if not define in any <record> node.

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.

4 participants