Skip to content

fix(wal): reject entries with non-string key or value - #344

Open
PhaeezAli wants to merge 1 commit into
danieldeer:mainfrom
PhaeezAli:fix/wal-reject-non-string-entries
Open

PhaeezAli wants to merge 1 commit into
danieldeer:mainfrom
PhaeezAli:fix/wal-reject-non-string-entries

Conversation

@PhaeezAli

@PhaeezAli PhaeezAli commented Oct 17, 2026 •

Copy link
Copy Markdown

Description

WalEntry.from_dict checked that key and value were present but not that they were strings. A hand-edited or corrupted log line such as {"op": "set", "key": null, "value": "d"} was replayed into the in-memory dict as a non-string key, which the engine never expects.

This raises TypeError for a non-string key or value, so replay() handles the line the same way it already handles other malformed records: it logs a warning and truncates the log to the last good entry.

The duplicate-field case in the issue is standard JSON last-value-wins and is left unchanged.

Closes #322

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Key Changes

  • from_dict raises TypeError when key is not a str, or when value is not a str for set entries.
  • Docstring Raises section updated to match.
  • Three new cases in test_replay_recovers_from_malformed_entry: null key, integer key, list value.

Validation

  • uv run pytest -q → 187 passed
  • uv run ruff check . and uv run ruff format --check . → clean
  • uv run ty check → clean
  • uv run --group docs scripts/docs-reference.py --check → up to date
  • Confirmed the three new test cases fail on main without the wal.py change and pass with it.

Checklist

  • I reviewed the diff and kept it focused on the described change.
  • Python changes pass uv run ruff check . and uv run ruff format --check ., or this PR does not change Python.
  • Changed behavior is covered by appropriate tests, including a regression test for bug fixes; any limitations are explained under Validation.
  • Validation lists the checks or manual flows I ran and their results.
  • Relevant documentation is updated, or no documentation change is needed.

Note

AI tooling has been used for: explaining the existing code path, reviewing my diff, and running the check commands. The fix and tests were written and validated by me.
Assisted by: GPTgo

WalEntry.from_dict only checked that key and value were present, not
that they were strings. A hand-edited or corrupted log line such as
{"op": "set", "key": null, "value": "d"} was replayed into the
in-memory dict as a non-string key, which the rest of the engine
never expects.

Raise TypeError for a non-string key or value so replay() treats the
line as corrupt, warns, and truncates the log to the last good entry,
the same as it already does for other malformed records.

Closes danieldeer#322
@PhaeezAli
PhaeezAli marked this pull request as ready for review October 17, 2026 19:21
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.

bug: Duplicates keys are not handled properly

2 participants