From 1289e03eac96f0df2deb0b2231c70228f4a9267a Mon Sep 17 00:00:00 2001 From: Ihor Barmak Date: Sat, 5 Sep 2026 19:41:11 +0300 Subject: [PATCH] [FIX] kw_api: allow API keys to be created on Odoo 17+ ApiKey.create used the pre-17 single-dict signature: @api.model def create(self, vals): vals['api_key'] = secrets.token_urlsafe(120) Since Odoo 17 the ORM passes create() a list of dicts, so that subscript raises TypeError: list indices must be integers or slices, not str, and no new API key can be created at all - through the UI or the ORM. Existing keys are plain rows and keep authenticating, so the module looks healthy until the first key rotation, the first extra API consumer, or the first fresh database. Switched to @api.model_create_multi and the key is generated per record. Verified on Odoo 19.0: a single-dict create and a two-record batch both succeed and produce distinct keys. Closes #1 --- kw_api/__manifest__.py | 2 +- kw_api/models/api_key.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kw_api/__manifest__.py b/kw_api/__manifest__.py index 6c29880..4495bbc 100644 --- a/kw_api/__manifest__.py +++ b/kw_api/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'Kitworks API', - 'version': '19.0.1.4.2', + 'version': '19.0.1.4.3', 'license': 'LGPL-3', 'category': 'KW API', diff --git a/kw_api/models/api_key.py b/kw_api/models/api_key.py index d2b01b0..fd7411e 100644 --- a/kw_api/models/api_key.py +++ b/kw_api/models/api_key.py @@ -40,10 +40,11 @@ class ApiKey(models.Model): 'API-key must be unique', ) - @api.model - def create(self, vals): - vals['api_key'] = secrets.token_urlsafe(120) - return super(ApiKey, self).create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + vals['api_key'] = secrets.token_urlsafe(120) + return super().create(vals_list) def update_api_key(self): self.ensure_one()