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

Silence Environment.manage warning in Odoo 15 #45

Merged
merged 2 commits into from
Oct 8, 2021

Conversation

sbidoul
Copy link
Member

@sbidoul sbidoul commented Oct 7, 2021

closes #43

And a few other internal improvements.

@codecov-commenter
Copy link

codecov-commenter commented Oct 7, 2021

Codecov Report

Merging #45 (e970c6c) into master (506f5f8) will increase coverage by 0.95%.
The diff coverage is 82.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #45      +/-   ##
==========================================
+ Coverage   83.85%   84.81%   +0.95%     
==========================================
  Files           6        7       +1     
  Lines         223      237      +14     
  Branches       31       33       +2     
==========================================
+ Hits          187      201      +14     
  Misses         25       25              
  Partials       11       11              
Impacted Files Coverage Δ
click_odoo/compat.py 77.77% <77.77%> (ø)
click_odoo/__init__.py 100.00% <100.00%> (ø)
click_odoo/env.py 80.76% <100.00%> (+8.26%) ⬆️
click_odoo/env_options.py 94.23% <100.00%> (+0.05%) ⬆️

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 506f5f8...e970c6c. Read the comment docs.

@sbidoul sbidoul force-pushed the silence-env-manage-warning-sbi branch from aa3b89c to cbf4810 Compare October 7, 2021 13:43
Also, refactor to isolate most compatibility code in a dedicated module
where it will be easier to locate when we drop older versions.
@sbidoul sbidoul force-pushed the silence-env-manage-warning-sbi branch from cbf4810 to e970c6c Compare October 7, 2021 13:48
Copy link

@joao-p-marques joao-p-marques left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes @sbidoul 👍

I am trying this patch but I am still getting warnings when using this in conjunction with click-odoo-contrib, when hitting this line:

with odoo.api.Environment.manage():

2021-10-08 09:06:25,941 1 WARNING ? py.warnings: /usr/local/lib/python3.8/contextlib.py:113: DeprecationWarning: Since Odoo 15.0, Environment.manage() is useless.
  File "/usr/local/bin/click-odoo-dropdb", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click_odoo/env_options.py", line 213, in _invoke
    with odoo.api.Environment.manage():
  File "/usr/local/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
2021-10-08 09:06:32,738 1 WARNING ? py.warnings: /usr/local/lib/python3.8/contextlib.py:113: DeprecationWarning: Since Odoo 15.0, Environment.manage() is useless.
  File "/usr/local/bin/click-odoo-initdb", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click_odoo/env_options.py", line 213, in _invoke
    with odoo.api.Environment.manage():
  File "/usr/local/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)

@sbidoul
Copy link
Member Author

sbidoul commented Oct 8, 2021

That's weird. Are you sure you are on the 15.0 branch and not 14.5 ?

@joao-p-marques
Copy link

That's weird. Are you sure you are on the 15.0 branch and not 14.5 ?

Yes, I am using the OCA/OCB fork but on branch 15.0.

The warning actually makes sense because the line I mentioned still makes a direct call to odoo.api.Environment.manage(), which should be replaced by a call to environment_manage(), as you did in the other cases, right?

Or is this line not supposed to be hit at all?

@sbidoul
Copy link
Member Author

sbidoul commented Oct 8, 2021

Ah right, I see it now. It should be fixed now. Thanks.

Copy link

@joao-p-marques joao-p-marques left a comment

Choose a reason for hiding this comment

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

Thanks 👍 Tested and works as expected now 🙂

@sbidoul sbidoul merged commit 47aea3c into master Oct 8, 2021
@acsone-git-bot acsone-git-bot deleted the silence-env-manage-warning-sbi branch October 8, 2021 14:05
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.

Environment.manage() is a noop in Odoo 15 and emits a Warning
4 participants