{"record":{"id":"c829ac7f258e507a","repo":"odoo/odoo","slug":"could-not-select-database-s","errorCode":null,"errorMessage":"Could not select database '%s'","messagePattern":"Could not select database '(.+?)'","errorType":"http","errorClass":"Exception","httpStatus":500,"severity":"error","filePath":"addons/base_import_module/controllers/main.py","lineNumber":16,"sourceCode":"# -*- coding: utf-8 -*-\nimport functools\n\nfrom odoo import _\nfrom odoo.exceptions import AccessError\nfrom odoo.http import Controller, route, request, Response\n\n\nclass ImportModule(Controller):\n    @route(\n        '/base_import_module/login_upload',\n        type='http', auth='none', methods=['POST'], csrf=False, save_session=False)\n    def login_upload(self, login, password, force='', mod_file=None, **kw):\n        try:\n            if not request.db:\n                raise Exception(_(\"Could not select database '%s'\", request.db))\n            credential = {'login': login, 'password': password, 'type': 'password'}\n            request.session.authenticate(request.env, credential)\n            # request.env.uid is None in case of MFA\n            if request.env.uid and request.env.user._is_admin():\n                return request.env['ir.module.module']._import_zipfile(mod_file, force=force == '1')[0]\n            raise AccessError(_(\"Only administrators can upload a module\"))\n        except Exception as e:\n            return Response(response=str(e), status=500)\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/odoo/odoo/blob/1e661df964b1b264c9cef3ab28430d4785be3fda/addons/base_import_module/controllers/main.py#L1-L25","documentation":"Raised by base_import_module's /base_import_module/login_upload endpoint when request.db is falsy - the HTTP request did not carry a database selector (no db in session/URL and no dbfilter match). The generic Exception is caught and returned as a 500 response body.","triggerScenarios":"POSTing to /base_import_module/login_upload against an Odoo host with multiple databases and no db parameter/cookie, or with a dbfilter that fails to single out a database; also on hosts where db is provided but the session state lost it.","commonSituations":"Custom deployment scripts hitting the endpoint directly with requests/curl without ?db=; multi-database instances without --db-filter; proxy stripping the db cookie.","solutions":["Target a single database explicitly: POST to /web?db=yourdb first (or pass db in the URL/cookie) so request.db is set, then call login_upload.","Configure --db-filter on the Odoo server so each host maps to exactly one database.","Send the session cookie from a prior /web/session/authentication request on the same db.","If only one database exists, ensure --no-database-list / database filtering leaves a single candidate."],"exampleFix":"# before\nrequests.post('http://odoo.example.com/base_import_module/login_upload',\n              data={'login': 'admin', 'password': '***'}, files={'mod_file': f})\n# -> 500 \"Could not select database 'False'\"\n\n# after: establish the db first\nimport requests\ns = requests.Session()\ns.post('http://odoo.example.com/web/session/authentication',\n       json={'params': {'login': 'admin', 'password': '***', 'db': 'mydb'}})\ns.post('http://odoo.example.com/base_import_module/login_upload',\n       data={'login': 'admin', 'password': '***'}, files={'mod_file': f})","handlingStrategy":"validation","validationCode":"import requests\n\ndef make_session(base_url: str, db: str, login: str, password: str) -> requests.Session:\n    s = requests.Session()\n    s.post(f'{base_url}/web/session/authentication',\n           json={'params': {'db': db, 'login': login, 'password': password}})\n    assert s.cookies.get('session_id'), 'no session: check db/login'\n    return s","typeGuard":null,"tryCatchPattern":"resp = requests.post(url, data=payload, files=files)\nif resp.status_code == 500 and \"Could not select database\" in resp.text:\n    raise RuntimeError('no db bound: pass db= or configure --db-filter') from None\nresp.raise_for_status()","preventionTips":["Always authenticate against /web/session/authentication with an explicit db first.","Configure --db-filter so each hostname resolves to exactly one database.","Script against a single-database host when possible to remove the ambiguity."],"tags":["odoo","module-import","http","multidb","deployment"],"backgroundTag":null,"analyzedSha":"1e661df964b1b264c9cef3ab28430d4785be3fda","analyzedAt":"2026-08-15T05:22:16.142Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}