diff options
| author | Toufik Ben Jaa <tbe@odoo.com> | 2019-01-04 09:45:43 +0000 |
|---|---|---|
| committer | Toufik Ben Jaa <tbe@odoo.com> | 2019-01-04 10:55:31 +0000 |
| commit | 99c319e03a0f08d87bdff95dc0578672fbe89961 (patch) | |
| tree | dc1098a45f3095914ccadddbfed650a3c04d36cb | |
| parent | 033608eb11cff4b983038388e9cba5dd3e02ffac (diff) | |
[FIX] account: deadlock on install
- When installing an accounting l10n module, the method `try_loading_for_current_company`
is called and could cause a deadlock.
The deadlock is caused by the fact that if the installation is started
via a web request the code tries to retrieve the current user's
company by doing `request.env.user.company_id`.
This causes issues since the installation code has its own postgresql
cursor while calling `request.env.user.company_id` will create its own
cursor.
So two cursors exists for the same Odoo worker.
The installation cursor asks for a lock on `res_users` while the
second cursor (the request one) will try to read on `res_users` and
wait the first lock to be dropped.
The lock is never dropped since the python code isn't running anymore
waiting for the `request.env.user.company_id` to be completed.
Causing the deadlock.
To fix the issue, we avoid the creation/usage of a cursor created by
`requesŧ`.
So to retrieve the current user's company, we read the user id on the
request's session, then browse the `res.user` record with the
installation cusror.
Fix issue introduced by commit d40956c7909bffa338fd0138565044571e852da3
closes odoo/odoo#29927
| -rw-r--r-- | addons/account/models/chart_template.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index df1bd50869c..6e4256cb230 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -165,9 +165,10 @@ class AccountChartTemplate(models.Model): of accounts had been created for it yet. """ self.ensure_one() - if request and request.db: - company_id = request.env.user.company_id.id - company = self.env['res.company'].browse(company_id) + # do not use `request.env` here, it can cause deadlocks + if request and request.session.uid: + current_user = self.env['res.users'].browse(request.uid) + company = current_user.company_id else: # fallback to company of current user, most likely __system__ # (won't work well for multi-company) @@ -185,9 +186,10 @@ class AccountChartTemplate(models.Model): rights. """ self.ensure_one() - if request and request.db: - company_id = request.env.user.company_id.id - company = self.env['res.company'].browse(company_id) + # do not use `request.env` here, it can cause deadlocks + if request and request.session.uid: + current_user = self.env['res.users'].browse(request.uid) + company = current_user.company_id else: # fallback to company of current user, most likely __system__ # (won't work well for multi-company) |
