[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 d40956c790
closes odoo/odoo#29927
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user