Repository: odoo/odoo

Issue #24071: [10.0/11.0] Expected singleton: res.users error for wrong username/password during authenticating session
Created: 2018-04-05T20:37:17Z
Impacted versions: 11.0
Steps to reproduce: Create POST request with following data
Host:
http://domain/web/session/authenticate
Header:
{'Content-Type': 'application/json'}
Body:
{
  "jsonrpc": "2.0",
  "method": "call",
  "id": 1,
  "params": {
    "login": "typo",
    "password": "admin",
    "db": "demo_db",
    "context": {}
  }
}

Current behavior:
If it has wrong Login or Password
{
    "error": {
        "message": "Odoo Server Error",
        "code": 200,
        "data": {
            "message": "Expected singleton: res.users()",
            "name": "builtins.ValueError",
            "exception_type": "internal_error",
            "arguments": [
                "Expected singleton: res.users()"
            ],
            "debug": "Traceback (most recent call last):\n  File \"/home/odoo_11/odoo/odoo/http.py\", line 647, in _handle_exception\n    return super(JsonRequest, self)._handle_exception(exception)\n  File \"/home/odoo_11/odoo/odoo/http.py\", line 307, in _handle_exception\n    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n  File \"/home/odoo_11/odoo/odoo/tools/pycompat.py\", line 87, in reraise\n    raise value\n  File \"/home/odoo_11/odoo/odoo/http.py\", line 689, in dispatch\n    result = self._call_function(**self.params)\n  File \"/home/odoo_11/odoo/odoo/http.py\", line 339, in _call_function\n    return checked_call(self.db, *args, **kwargs)\n  File \"/home/odoo_11/odoo/odoo/service/model.py\", line 97, in wrapper\n    return f(dbname, *args, **kwargs)\n  File \"/home/odoo_11/odoo/odoo/http.py\", line 332, in checked_call\n    result = self.endpoint(*a, **kw)\n  File \"/home/odoo_11/odoo/odoo/http.py\", line 933, in __call__\n    return self.method(*args, **kw)\n  File \"/home/odoo_11/odoo/odoo/http.py\", line 512, in response_wrap\n    response = f(*args, **kw)\n  File \"/home/odoo_11/odoo/addons/web/controllers/main.py\", line 786, in authenticate\n    return request.env['ir.http'].session_info()\n  File \"/home/odoo_11/odoo/addons/web_tour/models/ir_http.py\", line 12, in session_info\n    result = super(Http, self).session_info()\n  File \"/home/odoo_11/odoo/addons/barcodes/models/ir_http.py\", line 11, in session_info\n    res = super(IrHttp, self).session_info()\n  File \"/home/odoo_11/odoo/addons/web/models/ir_http.py\", line 28, in session_info\n    \"is_system\": request.env.user._is_system(),\n  File \"/home/odoo_11/odoo/odoo/addons/base/res/res_users.py\", line 578, in _is_system\n    self.ensure_one()\n  File \"/home/odoo_11/odoo/odoo/models.py\", line 4267, in ensure_one\n    raise ValueError(\"Expected singleton: %s\" % self)\nValueError: Expected singleton: res.users()\n"
        }
    },
    "jsonrpc": "2.0",
    "id": 1
}

If login and password is correct:
{
    "result": {
        "web_tours": [],
        "user_companies": false,
        "max_time_between_keys_in_ms": 55,
        "partner_id": 3,
        "session_id": "a99f731885245fkgnfdk8534565y6t65fdf",
        "is_system": true,
        "server_version": "11.0",
        "uid": 1,
        "currencies": {
            "1": {
                "symbol": "€",
                "digits": [
                    69,
                    2
                ],
                "position": "after"
            },
            "3": {
                "symbol": "$",
                "digits": [
                    69,
                    2
                ],
                "position": "before"
            },
            "21": {
                "symbol": "₹",
                "digits": [
                    69,
                    2
                ],
                "position": "after"
            }
        },
        "server_version_info": [
            11,
            0,
            0,
            "final",
            0,
            ""
        ],
        "web.base.url": domain,
        "name": "Administrator",
        "db": "demo",
        "user_context": {
            "tz": "Asia/Calcutta",
            "uid": 1,
            "lang": "en_US"
        },
        "is_superuser": true,
        "username": "admin",
        "company_id": 1
    },
    "jsonrpc": "2.0",
    "id": 1
}


Expected behavior: It should be Valid Response.
Video/Screenshot link (optional):

Duplicate issue #25650: Singleton error in authenticate API
Created: 2018-07-07T11:41:37Z
Impacted versions:
10.0 and 11.0
Steps to reproduce:
Affected API: /web/session/authenticate
Providing wrong credentials results in singleton error. I am able to reproduce in the odoo runbot.
A proper response has to shown.
Sample Request:
{
    "params":{
             "login":"admin",
             "password":"admin1",
             "db":"346136-11-0-cf1ec5-all"
   }
}

Current behavior:
Response:
{
    "jsonrpc": "2.0",
    "id": null,
    "error": {
        "code": 200,
        "message": "Odoo Server Error",
        "data": {
            "name": "builtins.ValueError",
            "debug": "Traceback (most recent call last):\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/http.py\", line 650, in _handle_exception\n    return super(JsonRequest, self)._handle_exception(exception)\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/http.py\", line 310, in _handle_exception\n    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/tools/pycompat.py\", line 87, in reraise\n    raise value\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/http.py\", line 692, in dispatch\n    result = self._call_function(**self.params)\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/http.py\", line 342, in _call_function\n    return checked_call(self.db, *args, **kwargs)\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/service/model.py\", line 97, in wrapper\n    return f(dbname, *args, **kwargs)\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/http.py\", line 335, in checked_call\n    result = self.endpoint(*a, **kw)\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/http.py\", line 936, in __call__\n    return self.method(*args, **kw)\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/http.py\", line 515, in response_wrap\n    response = f(*args, **kw)\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/addons/web/controllers/main.py\", line 787, in authenticate\n    return request.env['ir.http'].session_info()\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/addons/web_tour/models/ir_http.py\", line 12, in session_info\n    result = super(Http, self).session_info()\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/addons/barcodes/models/ir_http.py\", line 11, in session_info\n    res = super(IrHttp, self).session_info()\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/addons/web/models/ir_http.py\", line 28, in session_info\n    \"is_system\": request.env.user._is_system(),\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/addons/base/res/res_users.py\", line 618, in _is_system\n    self.ensure_one()\n  File \"/home/odoo/runbot/runbot/runbot/static/build/346136-11-0-cf1ec5/odoo/models.py\", line 4362, in ensure_one\n    raise ValueError(\"Expected singleton: %s\" % self)\nValueError: Expected singleton: res.users()\n",
            "message": "Expected singleton: res.users()",
            "arguments": [
                "Expected singleton: res.users()"
            ],
            "exception_type": "internal_error"
        }
    }
}

Expected behavior:
Response:
{
    "jsonrpc": "2.0",
    "id": null,
    "result": {
        "username": "admin",
        "user_context": {            
            "lang": "en_US",
            "tz": "Europe/Brussels",
            "uid": 1
        },
        "uid": 1,
        "db": "346136-11-0-cf1ec5-all",
        "company_id": 1,
        "session_id": "11a5a8de3f3fe82f2dabeec9f9cd4c2182d0fd1b",
        "partner_id": 3
    }
}

Video/Screenshot link (optional):

Closing comment (2018-07-07T13:05:15Z): Duplicate of #24071