Skip to content

[17.0][OU-ADD] base_automation: migration to 17.0#5028

Merged
pedrobaeza merged 2 commits into
OCA:17.0from
petrus-v:17.0-fix-base_automation
May 27, 2025
Merged

[17.0][OU-ADD] base_automation: migration to 17.0#5028
pedrobaeza merged 2 commits into
OCA:17.0from
petrus-v:17.0-fix-base_automation

Conversation

@petrus-v

@petrus-v petrus-v commented May 13, 2025

Copy link
Copy Markdown

attempt to take care some reviews from #4459

@legalsylvain

Copy link
Copy Markdown
Contributor

/ocabot migration base_automation

@OCA-git-bot OCA-git-bot added this to the 17.0 milestone May 13, 2025
@OCA-git-bot

Copy link
Copy Markdown
Contributor

The migration issue (#4124) has not been updated to reference the current pull request because a previous pull request (#4459) is not closed.
Perhaps you should check that there is no duplicate work.
CC @daiduongnguyen-odoo

@MiquelRForgeFlow MiquelRForgeFlow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand only create column with Null values should do the trick, any advices welcomes

_new_columns = [
    ("base.automation", "trg_field_ref", "many2one_reference"),
    ("base.automation", "trg_selection_field_id", "many2one"),
]

openupgrade.add_columns(env, _new_columns)

I'm wondering what's wrong moving forwards ? it is to gives more times to sub modules to change code as well and take care new values ?

I don't know. That's something only @pedrobaeza should answer, as he made that comment.

Comment thread openupgrade_scripts/scripts/base_automation/17.0.1.0/post-migration.py Outdated
@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

/ocabot migration base_automation

@petrus-v

Copy link
Copy Markdown
Author

@MiquelRForgeFlow thanks for review and advices.

I understand only create column with Null values should do the trick, any advices welcomes

_new_columns = [
    ("base.automation", "trg_field_ref", "many2one_reference"),
    ("base.automation", "trg_selection_field_id", "many2one"),
]

openupgrade.add_columns(env, _new_columns)

Here my question was not how to create those empty fields, but: if I only create those fields leaving them empty is it enough in this specific case ?

As far I understand, generally we do that for performance reason by populate the field using SQL query re-implementing the business python code in SQL. here the python code that compute trg_selection_field_id was not clear to me what it really does:

    @api.depends('trigger', 'trigger_field_ids')
    def _compute_trg_selection_field_id(self):
        to_reset = self.filtered(lambda a: a.trigger not in ['on_priority_set', 'on_state_set'] or len(a.trigger_field_ids) != 1)
        to_reset.trg_selection_field_id = False
        for automation in (self - to_reset):
            # always re-assign to an empty value to make sure we have no discrepencies
            automation.trg_selection_field_id = self.env['ir.model.fields.selection']

as far I understand the value is False or an empty recordset which is also a falsy value or I missed interpret the following instruction ?

>>> self.env['ir.model.fields.selection'].id
False

also when I read the doc

These scripts are about optimization. As a contributor of openupgrade for a module, if you do not have a problem of excessive > duration, you can propose migration scripts without such optimizations, especially when the SQL queries are complex to write.

Another contributor can always propose a PR for performance improvement, if he faces this problem.

And seen only 4 records in my database I was thinking should I take this risks !

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

Here my question was not how to create those empty fields, but: if I only create those fields leaving them empty is it enough in this specific case ?

Yeah, in this specific case, leaving them empty is fine 😊 (it's a new functionality, they are supposed to be filled using the form view)

@MiquelRForgeFlow MiquelRForgeFlow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread openupgrade_scripts/scripts/base_automation/17.0.1.0/end-migration.py Outdated
Comment thread openupgrade_scripts/scripts/base_automation/17.0.1.0/end-migration.py Outdated
@petrus-v petrus-v force-pushed the 17.0-fix-base_automation branch from 2d3653c to 13cd53e Compare May 27, 2025 15:26
@pedrobaeza

Copy link
Copy Markdown
Member

And please reduce the commit history to one commit.

@pedrobaeza

Copy link
Copy Markdown
Member

Well, 2 commits, the other and yours, but don't put so many commits of your authorship.

* move m2o_to_x2m in post migration
* move action server base automation name as end script
* rotate webhook uuid
* create trg_field_ref/trg_selection_field_id at pre-migration step
* revert _base_automation_update_deprecate_trigger to keep deprecated until next version
@petrus-v petrus-v force-pushed the 17.0-fix-base_automation branch from 13cd53e to 8b29020 Compare May 27, 2025 16:30
@petrus-v

Copy link
Copy Markdown
Author

I've squashed commits ! (I kept it in the mean time with the hope to help reviews)

@pedrobaeza pedrobaeza merged commit cdf1824 into OCA:17.0 May 27, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants