Skip to content

fix(sdk/python/core): raise clear KeeperError for malformed InMemoryKeyValueStorage config (KSM-299)#1057

Open
mgallego-keeper wants to merge 6 commits into
release/sdk/python/core/v17.4.0from
KSM-299-inmemory-storage-malformed-config-error
Open

fix(sdk/python/core): raise clear KeeperError for malformed InMemoryKeyValueStorage config (KSM-299)#1057
mgallego-keeper wants to merge 6 commits into
release/sdk/python/core/v17.4.0from
KSM-299-inmemory-storage-malformed-config-error

Conversation

@mgallego-keeper

Copy link
Copy Markdown
Contributor

Summary

InMemoryKeyValueStorage raised a cryptic TypeError: object of type 'NoneType' has no len() when constructed with a config string that is not valid JSON or base64-encoded JSON (e.g. InMemoryKeyValueStorage("A")). This fixes KSM-299 so a malformed config produces a clear, actionable KeeperError.

Root cause

In storage.py the string-config branch reassigns config to the result of json_to_dict(config) (which is None for invalid JSON), then builds the error with ... % str(len(config)). Python evaluates the len(config) operand before constructing the KeeperError, so len(None) raises TypeError first — the intended "Could not load config data" message never surfaces.

Fix

  • Keep the original config string in config_str and report its length, so the error path no longer calls len() on the parsed (possibly None) result.
  • The message now explains the problem: Could not load config data. The configuration string is not valid JSON or base64-encoded JSON (text length: N).

Tests

Added two regression tests to config_error_test.py, following the existing "must raise KeeperError, not TypeError" pattern:

  • single-character config ("A") — the exact ticket repro
  • a non-JSON, non-base64 string

Verified locally: full config_error_test.py passes (17 tests) and the version smoke test passes.

Release / version

  • Bumps python-core 17.3.0 → 17.4.0 across the three coupled locations (_version.py, the keeper_globals.py hardcoded fallback, and the smoke_test.py assertions).
  • Adds a consolidated ### 17.4.0 README changelog covering KSM-299 and the other fixes staged on this release branch (KSM-1019, KSM-1080, KSM-1085).

Notes for reviewers

stas-schaller and others added 6 commits July 8, 2026 12:56
…eyValueStorage config (KSM-299)

InMemoryKeyValueStorage given a config string that is not valid JSON (or
base64-encoded JSON) raised a cryptic "TypeError: object of type 'NoneType'
has no len()". The error path called len() on the json_to_dict() result
(None) instead of the source string, and %-formatting evaluated that len()
argument before the KeeperError could even be constructed.

Preserve the original config string in config_str and report its length, so
a malformed config now raises a clear KeeperError explaining the problem.
Add regression tests mirroring the existing "must raise KeeperError, not
TypeError" pattern in this suite.
Bump python-core from 17.3.0 to 17.4.0 across the three coupled locations
(_version.py, the keeper_globals.py hardcoded fallback, and the smoke_test
version assertions) and add a 17.4.0 README changelog entry covering
KSM-299, KSM-1019, KSM-1080 and KSM-1085.
mgallego-keeper added a commit that referenced this pull request Jul 9, 2026
…d into 17.4.0)

This fix is being consolidated into the 17.4.0 release. The single version
bump and the KSM-1019 changelog entry now live in the 17.4.0 release PR
(#1057), so revert _version.py, keeper_globals.py, smoke_test.py and the
README changelog back to the release-branch baseline. This PR now carries
only the KSMCache code fix and its regression tests.
@mgallego-keeper mgallego-keeper self-assigned this Jul 9, 2026
@stas-schaller
stas-schaller force-pushed the release/sdk/python/core/v17.4.0 branch from d541f29 to c80bdd5 Compare July 24, 2026 17:38
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.

2 participants