Skip to content

Instantly share code, notes, and snippets.

@bealdav
Forked from rvalyi/http.py
Created August 19, 2020 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bealdav/6cf9d0259387479ea9a47d033acd1f31 to your computer and use it in GitHub Desktop.
Save bealdav/6cf9d0259387479ea9a47d033acd1f31 to your computer and use it in GitHub Desktop.
import logging
import odoo
from odoo import http
from odoo.tools import config
_logger = logging.getLogger(__name__)
# similar to odoo.http.db_monodb but forcing the PRODUCTION_DB database
# in case there are several databases and request (like portal/website)
# doesn't specify any database.
def db_monodb_patched(httprequest=None):
"""
Magic function to find the current database.
Implementation details:
* Magic
* More magic
Returns ``None`` if the magic is not magic enough.
"""
httprequest = httprequest or request.httprequest
dbs = http.db_list(True, httprequest)
# try the db already in the session
db_session = httprequest.session.db
if db_session in dbs:
return db_session
# if there is only one possible db, we take that one
if len(dbs) == 1:
return dbs[0]
elif config.get('db_name') in dbs and not httprequest.args.get('db'):
_logger.info("request %s with database ambiguity: "
"forcing production database: %s" % (httprequest.path,
config['db_name'],))
return config['db_name']
return None
http.db_monodb = db_monodb_patched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment