-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[FIX] user_threshold: Don't create or commit new cursor #955
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] user_threshold: Don't create or commit new cursor #955
Conversation
* Remove new cursor creation/commit in favor of using current cursor
9f58d64 to
8c72f30
Compare
|
Odoo has many hooks everywhere in the modules loading process, so that we can integrate where we want. The I think we should use the IMO, the right fix is: diff --git a/user_threshold/models/res_users.py b/user_threshold/models/res_users.py
index b26151215b2..3f5a5bc7679 100644
--- a/user_threshold/models/res_users.py
+++ b/user_threshold/models/res_users.py
@@ -6,7 +6,7 @@ import os
from csv import reader
from lxml import etree
-from odoo import SUPERUSER_ID, _, api, fields, models, registry
+from odoo import _, api, fields, models
from odoo.exceptions import AccessError, ValidationError
from .ir_config_parameter import THRESHOLD_HIDE, MAX_DB_USER_PARAM
@@ -20,7 +20,7 @@ class ResUsers(models.Model):
'Exempt User From User Count Thresholds',
)
- def __init__(self, pool, cr):
+ def _register_hook(self):
"""
Override to check if env var to hide threshold configuration and
reset the database state is set. If it is, run those actions
@@ -28,24 +28,15 @@ class ResUsers(models.Model):
if THRESHOLD_HIDE:
exempt_users_var = os.environ.get('USER_THRESHOLD_USER', '')
exempt_users = reader([exempt_users_var])
- with api.Environment.manage():
- with registry(cr.dbname).cursor() as new_cr:
- new_env = api.Environment(new_cr, SUPERUSER_ID, {})
- installed = new_env['ir.module.module'].search_count([
- ('name', '=', 'user_threshold'),
- ('state', '=', 'installed'),
- ])
- if installed:
- users = new_env['res.users'].search([
- ('share', '=', False),
- ('threshold_exempt', '=', True),
- ])
- non_ex = users.filtered(
- lambda r: r.login not in exempt_users
- )
- for user in non_ex:
- user.threshold_exempt = False
- new_cr.commit()
+ users = self.env['res.users'].search([
+ ('share', '=', False),
+ ('threshold_exempt', '=', True),
+ ])
+ non_ex = users.filtered(lambda r: r.login not in exempt_users)
+ for user in non_ex:
+ user.threshold_exempt = False
def _check_thresholds(self):
""" |
|
Thanks @sylvain-garancher - I had no idea about |
91d11c1 to
60d1d3e
Compare
|
Oops, sorry, I forgot the decorator... |
user_threshold/models/res_users.py
Outdated
|
|
||
| def __init__(self, pool, cr): | ||
| @api.model_cr | ||
| def _register_hook(self, pool, cr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply def _register_hook(self):? We are in v10 api!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annnnnnd now I have actually RTFM. This is why blindly copying code is probably a bad idea lmao
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have copy-pasted my patch :D
|
Travis still fails on |
|
A PEP8 error you added in the last commit: And other lint errors not related to your changes: |
|
Oops forgot about this. We should be 🍏 now! |
8adf04e to
a3117d4
Compare
* [FIX] user_threshold: Don't create or commit new cursor * Remove new cursor creation/commit in favor of using current cursor
* [FIX] user_threshold: Don't create or commit new cursor * Remove new cursor creation/commit in favor of using current cursor
Syncing from upstream OCA/server-tools (15.0)
REF #889 (comment)