[FIX][module_auto_update] Record base addon checksum - #948
Conversation
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.
|
Travis is failing |
Tests adapted to new state change detection system.
|
Tests fixed |
|
💚 now |
| # Update base addon checksum if its state changed | ||
| base.invalidate_cache() | ||
| if base.state != pre_state: | ||
| base.latest_version = base.latest_version |
There was a problem hiding this comment.
Why don't you directly record the checksum instead of doing this weird reassignment?
There was a problem hiding this comment.
Or maybe a comment indicating why weird assignment is necessary if this is some edge case?
| for r in self: | ||
| r.checksum_installed = r.checksum_dir | ||
| elif vals.get('state') == 'uninstalled': | ||
| try: |
There was a problem hiding this comment.
I prefer the other approach:
version = vals.get('latest_version')
if version is None:
returnThere was a problem hiding this comment.
EAFP approach is more Pythonic in instances of key/attribute errors
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
I don't and I won't put it on any of my code, but I won't block this time.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I wasn't trying to start a flamewar here. It's very easy:
- Odoo stores
Falsefor empty fields, always, so no need to check if there'sNoneor 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!
There was a problem hiding this comment.
#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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Or maybe a comment indicating why weird assignment is necessary if this is some edge case?
|
5 days passed... |
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Syncing from upstream OCA/server-tools (12.0)
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_versionkey in the create/write dict. This is because Odoo will always set that field toFalsewhen 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