[IMP] load_data: allow to modify xml file before loading#452
Conversation
4262e5a to
7738930
Compare
|
Hi. Thanks a lot for the work. I'm in favor of such move. I have an idea to maybe "improve" your proposal. maybe it's not a good one, let me know ! Your proposal My proposal def load_data(env_or_cr, module_name, filename, idref=None, mode="init"):
# given a filename "BASE_FILENAME.xml"
# check if a file named "BASE_FILENAME.patches.xml" exists
# if yes, load it and apply transformations to BASE_FILENAME.xml
# Then, classic load_data algorithm.exemple of <?xml version="1.0" encoding="UTF-8"?>
<transformations>
<!-- comment 1: why i want to disable this section -->
<xpath expr="//record[@id='user_admin']" position="replace" />
<!-- comment 2: ... -->
<xpath expr="//record[@id='user_root']" position="replace" />
</transformations>Note : def load_data(env_or_cr, module_name, filename, idref=None, mode="init"; transformation_filename=None): |
|
thanks @legalsylvain, see your point. I'll prefer passing |
I think that the option you want is in the "spirit" of OpenUpgrade. I remember a few years ago, a discussion about 2 options :
-> and the result was "better to be explicit". so in the same way, better to add a xml_transformation_filename parameter. A single question : you talk about conditional loading in the first comment. If it's an interesting feature, maybe it's better to implement a
|
|
for that use case I'll rather have this support a file-like object, that the user fills however they see fit. but let's not overthink this, just a filename will be fine for now |
|
@OCA/openupgrade-maintainers : any extra PoV about that topic ? |
|
@legalsylvain I'd be happy with the |
7738930 to
7724a8a
Compare
|
thanks all, I've updated the code accordingly and the PR using this is indeed nicer now. Wrong XML there then also is detected in checks as expected: |
7724a8a to
22ee9a4
Compare
22ee9a4 to
25d4d2f
Compare
|
Hi @hbrunn. I don't understand why xml-check fail with the xml you propose. it is valid ? Or did i missed something ? |
|
I deliberately added a mistake, which I didn't commit of course |
sorry, I misread your comment. all is OK, then ! thanks ! |
since we started automatically generating the analysis for openupgrade, it bothers me that we have to do changes to xml files in a copy of the generated file.
So here I propose to allow users of openupgradelib to change the file while loading, this way there's no need to change stuff in the file at all, and if the changes are crafted sufficiently defensively, they should survive any subsequent changes of the
noupdate_changes.xmlfile.With this, ie in the base module instead of copying the changes file, we write
This also allows us to load some noupdate changes conditionally, as in the case I'm working on currently: Update a product's UOM if it's not used in invoices already, don't otherwise(that's not what I ended up doing, but it's a possibility anyways)