Skip to content

[FIX] kw_api: allow API keys to be created on Odoo 17+ - #3

Open
brmk wants to merge 1 commit into
kitworks-systems:19.0from
Uplab:fix/api-key-create-odoo17
Open

[FIX] kw_api: allow API keys to be created on Odoo 17+#3
brmk wants to merge 1 commit into
kitworks-systems:19.0from
Uplab:fix/api-key-create-odoo17

Conversation

@brmk

@brmk brmk commented Sep 5, 2026

Copy link
Copy Markdown

Fixes #1.

ApiKey.create uses the pre-17 single-dict signature, so on Odoo 17+ it receives the ORM's
list of dicts and raises TypeError: list indices must be integers or slices, not str. No
new API key can be created — through the UI or the ORM.

Existing keys are plain rows and keep authenticating, which is why this stays invisible: it
only bites on a key rotation, an extra API consumer, or a fresh database.

Switched to @api.model_create_multi, generating the key per record.

Verified

Odoo 19.0, kw_api installed:

before after
create({...}) single dict TypeError key created, 160 chars
create([{...}, {...}]) batch TypeError 2 records, 2 distinct keys

No behaviour change beyond the failure going away — the key is still generated server-side
and still ignores anything the caller passes in api_key.

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 kitworks-systems#1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant