Skip to content

[FIX][module_auto_update] Record base addon checksum - #948

Merged
pedrobaeza merged 3 commits into
OCA:9.0from
Tecnativa:9.0-module_auto_update-fix_base_endless_update
Aug 28, 2017
Merged

[FIX][module_auto_update] Record base addon checksum#948
pedrobaeza merged 3 commits into
OCA:9.0from
Tecnativa:9.0-module_auto_update-fix_base_endless_update

Conversation

@yajo

@yajo yajo commented Aug 23, 2017

Copy link
Copy Markdown
Member

Base addon is a special case: when getting updated, it is updated in a limited addons graph that only contains itself. Under such graph, no behavior modifications are respected, so no matter what we do in module_auto_update, it will get ignored in that step. This means that when we first install module_auto_update, it will record current base addon's dir hash, and it will never again be updated, so the next time your base addon is updated, the auto update will update all addons (as expected), and every next times too (not expected).

To fix that behavior, now we track the base addon status before and after running an upgrade. If it has changed, then we update its checksum.

Besides that, workarounds for odoo/odoo#18597 are removed, and a new method for knowing if an addon is being installed, updated or uninstalled is used: check the existence of latest_version key in the create/write dict. This is because Odoo will always set that field to False when removing the addon, and it will also always write to it after installing or updating, so it provides basically all the information we need to know if we have to update or remove the checksum.

@Tecnativa

Base addon is a special case: when getting updated, it is updated in a limited addons graph that only contains itself. Under such graph, no behavior modifications are respected, so no matter what we do in module_auto_update, it will get ignored in that step. This means that when we first install module_auto_update, it will record current base addon's dir hash, and it will never again be updated, so the next time your base addon is updated, the auto update will update all addons (as expected), and every next times too (not expected).

To fix that behavior, now we track the base addon status before and after running an upgrade. If it has changed, then we update its checksum.

Besides that, workarounds for odoo/odoo#18597 are removed, and a new method for knowing if an addon is being installed, updated or uninstalled is used: check the existence of `latest_version` key in the create/write dict. This is because Odoo will always set that field to `False` when removing the addon, and it will also always write to it after installing or updating, so it provides basically all the information we need to know if we have to update or remove the checksum.
@yajo yajo added this to the 9.0 milestone Aug 23, 2017
@yajo
yajo requested a review from lasley August 23, 2017 11:45
@yajo yajo self-assigned this Aug 23, 2017
@yajo
yajo requested a review from pedrobaeza August 23, 2017 11:46
@pedrobaeza

Copy link
Copy Markdown
Member

Travis is failing

Tests adapted to new state change detection system.
@yajo

yajo commented Aug 24, 2017

Copy link
Copy Markdown
Member Author

Tests fixed

@yajo

yajo commented Aug 24, 2017

Copy link
Copy Markdown
Member Author

💚 now

# Update base addon checksum if its state changed
base.invalidate_cache()
if base.state != pre_state:
base.latest_version = base.latest_version

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why don't you directly record the checksum instead of doing this weird reassignment?

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.

Or maybe a comment indicating why weird assignment is necessary if this is some edge case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Explanation added.

for r in self:
r.checksum_installed = r.checksum_dir
elif vals.get('state') == 'uninstalled':
try:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer the other approach:

version = vals.get('latest_version')
if version is None:
    return

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.

EAFP approach is more Pythonic in instances of key/attribute errors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need more lines and it's less readable (as you have to know what the exception means), so I prefer the other approach (and other Python gurus are saying the same lastly).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I also prefer EAFP

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't and I won't put it on any of my code, but I won't block this time.

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.

Do we know where vals comes from off-hand? I personally don't, but am assuming it's from a create or write method. Why would ORM restrict what vals are entered into a dictionary?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are you trying to get an impossible case for my code? It works very well and doesn't mean any error even on the improbable case of somebody consciously wants to ruin it, but hey, if you have a big problem with that, just leave it!

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 wasn't going for ruining it, I was just pointing out that this could have unintended side-effects outside of what we think.

The if version is False: is an incredibly explicit if statement that makes me think @yajo saw something in his testing where a False-type value can be in vals but not actually be a False. Maybe this is just a "0" version number; I'm not sure.

None is a False type value though - so while we may think it won't cause issues, this is why I asked @yajo for clarification to the explicit if in #948 (comment)

Honestly at this point I'd kind of like an inline comment to the edge case that the explicit if is covering. @yajo can you clarify for us in a comment why we are being so explicit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wasn't trying to start a flamewar here. It's very easy:

  • Odoo stores False for empty fields, always, so no need to check if there's None or whatever.
  • If above point is true always, it's even more in current case.
  • What would happen if a module is defined with "version": ""? This is very unlikely, and if it ever happened, I'm pretty sure Odoo would fail or patch it with "9.0" or "10.0" automatically, but... is it even worth it testing that? IMHO not.

So, if I wanted to use LBYL, the right code would be:

# Option A, matching 100% current behavior
if "latest_version" not in vals:
    return
# Option B, not 100%, but side matches would not matter since they should theoretically never happen
if vals.get("latest_version") is None:
    return

... but I didn't.

The fastest way to do it was as it is right now, and it uses EAFP because IMHO it's the pythonic way to do it.

However, there's one basic truth that we all have to acknowledge: Sometimes there's more than 1 way to do the same thing right. So, in case somebody else chooses a way that you wouldn't choose by yourself, but it's also a good way to get to the exact same result where the only difference is a matter of taste... why bother? Hakuna matata!


As a side note, kudos @lasley for finding out #948 (comment), a very nice addition to Python 3. I'm very eager to get it! ☺️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#948 (comment) is another sign that they have found EAFP very cluttered in code 😉 but hey, as you have said, there are several ways of doing things. You won't see me a lot doing EAFP though, not at least on that form.

for r in self:
r.checksum_installed = r.checksum_dir
elif vals.get('state') == 'uninstalled':
try:

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.

EAFP approach is more Pythonic in instances of key/attribute errors

# Update base addon checksum if its state changed
base.invalidate_cache()
if base.state != pre_state:
base.latest_version = base.latest_version

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.

Or maybe a comment indicating why weird assignment is necessary if this is some edge case?

@yajo

yajo commented Aug 28, 2017

Copy link
Copy Markdown
Member Author

5 days passed...

@pedrobaeza
pedrobaeza merged commit b8285b5 into OCA:9.0 Aug 28, 2017
@pedrobaeza
pedrobaeza deleted the 9.0-module_auto_update-fix_base_endless_update branch August 28, 2017 10:33
yajo added a commit to Tecnativa/server-tools that referenced this pull request Aug 29, 2017
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.
yajo added a commit to Tecnativa/server-tools that referenced this pull request Aug 30, 2017
yajo added a commit to Tecnativa/server-tools that referenced this pull request Aug 30, 2017
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
yajo added a commit to Tecnativa/server-tools that referenced this pull request Aug 30, 2017
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
yajo added a commit to Tecnativa/server-tools that referenced this pull request Aug 30, 2017
pedrobaeza pushed a commit to Tecnativa/server-tools that referenced this pull request Aug 30, 2017
pedrobaeza pushed a commit to Tecnativa/server-tools that referenced this pull request Aug 30, 2017
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
yajo added a commit to Tecnativa/server-tools that referenced this pull request Jan 5, 2018
yajo added a commit to Tecnativa/server-tools that referenced this pull request Jan 5, 2018
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
njeudy pushed a commit to njeudy/server-tools that referenced this pull request Jan 11, 2018
njeudy pushed a commit to njeudy/server-tools that referenced this pull request Jan 11, 2018
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
sbidoul pushed a commit to acsone/server-tools that referenced this pull request Mar 22, 2018
Angelfentanez pushed a commit to vauxoo-dev/server-tools that referenced this pull request Oct 1, 2018
Angelfentanez pushed a commit to vauxoo-dev/server-tools that referenced this pull request Oct 1, 2018
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
sbidoul pushed a commit to acsone/server-tools that referenced this pull request Oct 5, 2018
sbidoul pushed a commit to acsone/server-tools that referenced this pull request Oct 5, 2018
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
schout-it pushed a commit to schout-it/server-tools that referenced this pull request Oct 1, 2019
schout-it pushed a commit to schout-it/server-tools that referenced this pull request Oct 1, 2019
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 5, 2020
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 5, 2020
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 18, 2020
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 18, 2020
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 18, 2020
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 18, 2020
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 18, 2020
eantones pushed a commit to nuobit/server-tools that referenced this pull request May 18, 2020
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
manengel pushed a commit to initOS/server-tools that referenced this pull request Nov 30, 2020
manengel pushed a commit to initOS/server-tools that referenced this pull request Nov 30, 2020
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
mlaitinen pushed a commit to avoinsystems/server-tools that referenced this pull request Dec 27, 2021
mlaitinen pushed a commit to avoinsystems/server-tools that referenced this pull request Dec 27, 2021
The same problem that was fixed for the `base` addon in OCA#948 happened with random addons that do not depend on `module_auto_update` (a.k.a. any addon) that Odoo decided to load before that one in the graph.

Now we always check for all addons if their state has changed, and make sure to trigger the udpate mechanism that stores the right value in `installed_checksum_dir` field.

If you installed and uninstalled the addon right away, you'd get a ProgrammingError saying that some columns exist no more. Checks are done now using `search_read`, which lets us limit the fields being fetched, and the environment is cleared to make sure nothing fails.

Also we now guess if this own addon has been uninstalled and skip further logic if so, given it would hit broken triggers otherwise as it did before.
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (12.0)
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.

3 participants