Skip to content
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

Fix dependencies expansion: handle active=True correctly #93

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

Conversation

joao-p-marques
Copy link
Contributor

active=True in a module's manifest is a deprecated equivalent to auto_install=True:
odoo/odoo@2cc7f0d#diff-367842087e68d6811cf53f2ab3eb21103cd8e793b1648ef3e57f220ee0ccde4eL345

It does not mean that Odoo installs it automatically, as mentioned in #9

Instead, we should handle that key the same way we handle the auto_install one.

To reproduce

In v13 or v14, there is a localization module with active set to True: https://github.com/odoo/odoo/blob/13.0/addons/l10n_fi/__manifest__.py#L39
If we did click-odoo-initdb -n devel -m base, l10n_fi was added to the list of modules to generate the hash, along with its dependencies (one of them is account). However, after the initialization of the DB, Odoo did not install that module, which made that hash incorrect.
If we, then, removed the DB (click-odoo-dropdb devel) and initialized it again with account (click-odoo-initdb -n devel -m base,account) the result was that a DB cache was restored (because the previous hash included account) when, however, account was never installed in the DB.

@Tecnativa
TT24972

ping @yajo

@joao-p-marques
Copy link
Contributor Author

@sbidoul are the test errors related to this change?
I see that they fail for master too: https://github.com/acsone/click-odoo-contrib/runs/2064361001?check_suite_focus=true

@sbidoul
Copy link
Member

sbidoul commented Apr 15, 2021

The test failures are not related. We'll need a new test for this case though.

@joao-p-marques joao-p-marques force-pushed the fix-active-modules-hashing branch from da36cee to 1abcc06 Compare April 15, 2021 13:35
@joao-p-marques
Copy link
Contributor Author

joao-p-marques commented Apr 15, 2021

Ok, I added a simple test with this situation in particular, I don't know if it is the best way of testing this, but it tests at least this specific situation.

joao-p-marques added a commit to Tecnativa/doodba-copier-template that referenced this pull request Apr 16, 2021
joao-p-marques added a commit to Tecnativa/doodba-copier-template that referenced this pull request Apr 16, 2021
joao-p-marques added a commit to Tecnativa/doodba-copier-template that referenced this pull request Apr 19, 2021
joao-p-marques added a commit to Tecnativa/doodba-copier-template that referenced this pull request Apr 20, 2021
joao-p-marques added a commit to Tecnativa/doodba that referenced this pull request Apr 20, 2021
joao-p-marques added a commit to Tecnativa/doodba that referenced this pull request Apr 20, 2021
yajo pushed a commit to Tecnativa/doodba that referenced this pull request Apr 20, 2021
@sbidoul
Copy link
Member

sbidoul commented Apr 21, 2021

@joao-p-marques thanks for the fix! Can you rebase and add a newfragments/93.bugfix with a changelog entry ?

I don't know why we decided to handle active differently than auto_install in #9. That's weird.

@joao-p-marques joao-p-marques force-pushed the fix-active-modules-hashing branch from 1abcc06 to 2f0a3c2 Compare April 22, 2021 05:50
@joao-p-marques
Copy link
Contributor Author

Ok @sbidoul Thanks!

I just added newfragments/93.bugfix to my commit. Do I need to do anything else to update the changelog?

@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2021

Codecov Report

Merging #93 (01f6d5e) into master (478983c) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
- Coverage   93.16%   93.12%   -0.04%     
==========================================
  Files          14       14              
  Lines         892      887       -5     
  Branches      157      154       -3     
==========================================
- Hits          831      826       -5     
  Misses         43       43              
  Partials       18       18              
Impacted Files Coverage Δ
click_odoo_contrib/initdb.py 96.95% <100.00%> (ø)
click_odoo_contrib/manifest.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 478983c...01f6d5e. Read the comment docs.

@sbidoul
Copy link
Member

sbidoul commented Apr 22, 2021

Do I need to do anything else to update the changelog?

No that's fine, it will be updated when releasing.

Still I have doubts that auto_install and active mean exactly the same. For instance in the Odoo documentation, they are distinct entries. Is that a documentation bug ? I'd really like a test that reproduces the bug.

@joao-p-marques
Copy link
Contributor Author

Still I have doubts that auto_install and active mean exactly the same. For instance in the Odoo documentation, they are distinct entries. Is that a documentation bug ? I'd really like a test that reproduces the bug.

I think the documentation is buggy, at least from reading the code I mention above.

The test I add should assert that, at least for v13 and v14.

@yajo
Copy link
Contributor

yajo commented Aug 24, 2021

I'm patching the docs in odoo/documentation#1109 to clarify this situation. This fix has been in production for months, is all green and has proper docs and tests. IMHO this can be merged.

@joao-p-marques
Copy link
Contributor Author

@sbidoul any news on this? Could it be merged?

@sbidoul
Copy link
Member

sbidoul commented Oct 5, 2021

I'm still have doubts. For instance if l10n_fi is active = auto_install = True, why does it not auto install when we install account ?

@joao-p-marques
Copy link
Contributor Author

It has been some time since I've looked into it, but I think what you are saying is exactly what I am doing here.

If active = auto_install = True, the module will be installed if we install account and should be included in the hash.

However, the current behavior, is that it is always included, even if its dependencies are not installed (like account).

@sbidoul
Copy link
Member

sbidoul commented Oct 5, 2021

What I mean is that l10n_fi does not auto install in my databases when I do "odoo -i account", so active must be doing something different than auto_install ?

@joao-p-marques
Copy link
Contributor Author

Oh, I see... I think it is because Odoo defaults auto_install to False here and because of that, never actually gets here to read the active property.

I guess that is another bug, as by looking at the code you can see they should have the same behavior...

In that case, we can either leave this as is, or simply ignore the active keyword completely, as Odoo clearly does the same... The current behavior in click-odoo-contrib, however, is not correct IMHO.

@yajo
Copy link
Contributor

yajo commented Dec 23, 2021

It seems the docs have settled in odoo/documentation#1427. I'd say the patch is incomplete because it doesn't contemplate situations where active or auto_install is an empty or a non-empty list of modules, where behaviours would be still different.

@joao-p-marques
Copy link
Contributor Author

Thanks for the reference @yajo

I will work on the necessary changes 👍

@joao-p-marques joao-p-marques force-pushed the fix-active-modules-hashing branch from 2f0a3c2 to 8482199 Compare December 23, 2021 10:02
@joao-p-marques
Copy link
Contributor Author

@yajo @sbidoul taking into account the latest updates to the documentation, and also what I mentioned in #93 (comment) about the actual usage of the active keyword, I ended up:

  1. Ignoring the active keyword completely, as Odoo does the same. For further reference, AFAICS Odoo completely removes the active keyword in v15: https://github.com/odoo/odoo/blob/15.0/odoo/modules/module.py
  2. Applying the needed patch to handle the cases where auto_install is a set, although it was not possible to make a test as Odoo doesn't have a single implementation of it in the current modules.

…orrectly

According to the updated documentation, active=True in a module's manifest is a deprecated equivalent to auto_install=True:
odoo/odoo@2cc7f0d#diff-367842087e68d6811cf53f2ab3eb21103cd8e793b1648ef3e57f220ee0ccde4eL345
https://www.odoo.com/documentation/15.0/developer/reference/backend/module.html

it does not mean that Odoo installs it automatically, as mentioned in acsone#9

OTOH, currently Odoo ignores it. See:
https://github.com/odoo/odoo/blob/13.0/odoo/modules/module.py#L335
https://github.com/odoo/odoo/blob/13.0/odoo/modules/module.py#L370

So, we should ignore that key.

Besides, this implements the more complex functionality of defining auto_install as a subset of the module's dependencies, as also explained in the documentation.

Also, add a new simple test for this case.
@joao-p-marques joao-p-marques force-pushed the fix-active-modules-hashing branch from 8482199 to 01f6d5e Compare December 23, 2021 10:23
@yajo
Copy link
Contributor

yajo commented Feb 2, 2022

This has been more than half a year in production. Can't we merge?

@yajo
Copy link
Contributor

yajo commented Mar 17, 2022

Hello @sbidoul! 👋🏼

Any chances for a new review and merge?

@pedrobaeza
Copy link

@sbidoul coming again to this. Can this be merged?

if include_auto_install:
auto_install_list = []
for module_name in sorted(odoo.modules.module.get_modules()):
module_path = odoo.modules.get_module_path(module_name)
manifest = read_manifest(module_path)
if manifest.get("auto_install"):
# "auto_install" can be a list or a boolean
# see Odoo's documentation for Module Manifests
Copy link
Member

Choose a reason for hiding this comment

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

This part seems unrelated to the issue, and should be best done in another PR.
BTW, where is this documented?

Copy link
Member

Choose a reason for hiding this comment

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

NVM, I found the comment in the Odoo codebase.

Choose a reason for hiding this comment

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

Tell me and I put the link here as reference.

@@ -0,0 +1,3 @@
Fix dependencies expansion: handle active=True correctly
`active=True` in a module's manifest is a deprecated equivalent to `auto_install=True`,
so we should handle that key the same way we handle the `auto_install` one.
Copy link
Member

Choose a reason for hiding this comment

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

This description is incorrect? If I read the PR correctly, it ignores the active flag so it does not handle it the same way as auto_install.

if (
isinstance(auto_install, list)
and (
manifest.get("auto_install") == []
Copy link
Member

Choose a reason for hiding this comment

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

This does not look right. If auto_install is an empty list, the module should be installed unconditionally, so in that case it should be add_deps(module_name).

@sbidoul
Copy link
Member

sbidoul commented Oct 6, 2022

@pedrobaeza I read this again and I found a couple of issues, I think.

Also, it seem Odoo 12 still supported the active flag, so we should skip the check for active for Odoo >= 13.

@pedrobaeza
Copy link

OK, seeing that this is not direct at all, we can leave it on hold, and I'll come back to this later with less workload, and also not being something terrible. I haven't found a manifest with active for years...

Thank you very much for reviewing it. I'll tell you when the changes are done.

@sbidoul
Copy link
Member

sbidoul commented Oct 6, 2022

I haven't found a manifest with active for years...

Indeed :) Actually I think the real bug is that we don't support auto_install=[]. I'll create an issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants