[FIX] kw_api: allow API keys to be created on Odoo 17+ - #3
Open
brmk wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1.
ApiKey.createuses the pre-17 single-dict signature, so on Odoo 17+ it receives the ORM'slist of dicts and raises
TypeError: list indices must be integers or slices, not str. Nonew 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_apiinstalled:create({...})single dictcreate([{...}, {...}])batchNo behaviour change beyond the failure going away — the key is still generated server-side
and still ignores anything the caller passes in
api_key.