Skip to content

[IMP] util.update_record_from_xml #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KangOl
Copy link
Contributor

@KangOl KangOl commented Jul 2, 2025

Set the xml_filename argument of the xml_import records.

@KangOl KangOl requested a review from aj-fuentes July 2, 2025 14:24
@robodoo
Copy link
Contributor

robodoo commented Jul 2, 2025

Pull request status dashboard

@@ -1147,6 +1148,8 @@ def add_ref(ref):
doc = lxml.etree.parse(fp)
for node in doc.xpath(xpath):
found = True
if xml_filename is None and module == from_module:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we check module vs from_module? Don't we need to set the xml_filename to be the actual file always?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to avoid setting the filename when we load an overridden record (initially declared in another module).
However, the models that use this xml_filename (views, mail templates) are not usually changed by other modules (and even less updated via update_record_from_xml), so I can remove this condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should do what standard code does.

Set the `xml_filename` argument of the `xml_import` records.
@KangOl KangOl force-pushed the master-xml_filename-chs branch from a24211e to e6d1bdf Compare July 3, 2025 11:37
@@ -1147,6 +1148,8 @@ def add_ref(ref):
doc = lxml.etree.parse(fp)
for node in doc.xpath(xpath):
found = True
if xml_filename is None:
Copy link
Contributor

@aj-fuentes aj-fuentes Jul 3, 2025

Choose a reason for hiding this comment

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

I wonder if we now need the found variable? We can keep the xml_filename as the "found" signal whenever it's set. Maybe named found_in_xml_file?

There is a slight subtlety. We do not break the search loop when found. Thus in practice we keep searching and adding nodes to our new root. This means that we will be lying if we keep the same filename when loading our new root. Maybe we should have a new_root per found_in_xml_file, a sort of map filename->new_root. We should double check the standard behavior if we really care about this.

EDIT: This is obviously a corner case since it's a mistake to have two records with same xmlid redefined in the same module in xml. But this has been actually seen before. Aligning with standard code would be "saner" even for the corner case.

@KangOl
Copy link
Contributor Author

KangOl commented Jul 3, 2025

upgradeci retry with always only hr

@KangOl
Copy link
Contributor Author

KangOl commented Jul 4, 2025

After some tests, it doesn't work as expected in all cases.

  • ir.ui.view: works correctly due to the arch field being computed with an inverse function
  • theme.ir.ui.view: just read in the default function, so not updated during write
  • template.reset.mixin ({mail,sms}.template): set in the create overwrite only.

Maybe all those usages should be standardized in a common mixin which also handle the update.

@aj-fuentes
Copy link
Contributor

After some tests, it doesn't work as expected in all cases.

* `ir.ui.view`: works correctly due to the `arch` field being computed with an `inverse` function

* `theme.ir.ui.view`: just read in the `default` function, so not updated during `write`

* `template.reset.mixin` (`{mail,sms}.template`): set in the `create` overwrite only.

Maybe all those usages should be standardized in a common mixin which also handle the update.

I think this could be an option if this becomes more widely use. For current cases it looks very localized and (if I'm not mistaked) with a simple solution. The mixin may add extra complexity that we don't need for these few cases.

@KangOl
Copy link
Contributor Author

KangOl commented Jul 7, 2025

No, it's not enough. It should be set in create and write, like for other models.

@aj-fuentes
Copy link
Contributor

No, it's not enough. It should be set in create and write, like for other models.

What I had in mind was that the field should be a computed stored field, with "depends". I missed that it was just default=...

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.

3 participants