odoo/odoo · error · Exception

Could not select database '%s'

Error message

Could not select database '%s'

What it means

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.

Source

Thrown at addons/base_import_module/controllers/main.py:16

# -*- coding: utf-8 -*-
import functools

from odoo import _
from odoo.exceptions import AccessError
from odoo.http import Controller, route, request, Response


class ImportModule(Controller):
    @route(
        '/base_import_module/login_upload',
        type='http', auth='none', methods=['POST'], csrf=False, save_session=False)
    def login_upload(self, login, password, force='', mod_file=None, **kw):
        try:
            if not request.db:
                raise Exception(_("Could not select database '%s'", request.db))
            credential = {'login': login, 'password': password, 'type': 'password'}
            request.session.authenticate(request.env, credential)
            # request.env.uid is None in case of MFA
            if request.env.uid and request.env.user._is_admin():
                return request.env['ir.module.module']._import_zipfile(mod_file, force=force == '1')[0]
            raise AccessError(_("Only administrators can upload a module"))
        except Exception as e:
            return Response(response=str(e), status=500)

View on GitHub (pinned to 1e661df964)

Solutions

  1. 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.
  2. Configure --db-filter on the Odoo server so each host maps to exactly one database.
  3. Send the session cookie from a prior /web/session/authentication request on the same db.
  4. If only one database exists, ensure --no-database-list / database filtering leaves a single candidate.

Example fix

# before
requests.post('http://odoo.example.com/base_import_module/login_upload',
              data={'login': 'admin', 'password': '***'}, files={'mod_file': f})
# -> 500 "Could not select database 'False'"

# after: establish the db first
import requests
s = requests.Session()
s.post('http://odoo.example.com/web/session/authentication',
       json={'params': {'login': 'admin', 'password': '***', 'db': 'mydb'}})
s.post('http://odoo.example.com/base_import_module/login_upload',
       data={'login': 'admin', 'password': '***'}, files={'mod_file': f})
Defensive patterns

Strategy: validation

Validate before calling

import requests

def make_session(base_url: str, db: str, login: str, password: str) -> requests.Session:
    s = requests.Session()
    s.post(f'{base_url}/web/session/authentication',
           json={'params': {'db': db, 'login': login, 'password': password}})
    assert s.cookies.get('session_id'), 'no session: check db/login'
    return s

Try / catch

resp = requests.post(url, data=payload, files=files)
if resp.status_code == 500 and "Could not select database" in resp.text:
    raise RuntimeError('no db bound: pass db= or configure --db-filter') from None
resp.raise_for_status()

Prevention

When it happens

Trigger: 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.

Common situations: Custom deployment scripts hitting the endpoint directly with requests/curl without ?db=; multi-database instances without --db-filter; proxy stripping the db cookie.

Related errors


AI-assisted analysis of odoo/odoo@1e661df964 (2026-08-15). Data as JSON: /api/errors/c829ac7f258e507a. Report an issue: GitHub.