[FIX] website: prevent crash when 'force_website_id' has been deleted
As an admin or website publisher, you have the possibility to switch website in the navbar. This will force a website in your session*. If this website is removed at some point, your session will be broken as the dispatch will lead to a traceback, trying to read un unexisting website. * There is other way to have the website forced in the session: theme install, go to website from settings, create website from settings.. opw-2092845 X-original-commit: 835d1201b8a26168bb003a5fc664e692005cb0a2
This commit is contained in:
@@ -519,7 +519,12 @@ class Website(models.Model):
|
||||
@api.model
|
||||
def get_current_website(self, fallback=True):
|
||||
if request and request.session.get('force_website_id'):
|
||||
return self.browse(request.session['force_website_id'])
|
||||
website_id = self.browse(request.session['force_website_id']).exists()
|
||||
if not website_id:
|
||||
# Don't crash is session website got deleted
|
||||
request.session.pop('force_website_id')
|
||||
else:
|
||||
return website_id
|
||||
|
||||
website_id = self.env.context.get('website_id')
|
||||
if website_id:
|
||||
|
||||
Reference in New Issue
Block a user