Repository navigation
Conversation
… backend The memory backend ignored SET x = list_append(...) and SET x = if_not_exists(x, :v), so atomic append, prepend, and if_not_exists updates were silent no-ops. SET operands are now evaluated like DynamoDB: list_append concatenates in argument order, if_not_exists falls back when the path is missing, and a missing path or a non-list operand raises ValidationException. Updates are applied to a copy so a rejected expression leaves the stored item unchanged. MemoryClient also gains count() and sync_count() with the same arguments and return shape as DynamoDBClient, so Model.count() works in tests.
vicolby
marked this pull request as draft
October 31, 2026 06:06
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
vicolby
marked this pull request as ready for review
October 31, 2026 06:32
vicolby
marked this pull request as draft
October 31, 2026 06:35
vicolby
marked this pull request as ready for review
November 7, 2026 03:46
Build the atomic operation list before the pytest.raises block so only sync_update can raise inside it (SonarCloud python:S5778).
|
This branch has not been deployed
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.



Intent
Fix two gaps in the pydynox in-memory testing backend, found while fixing the docs examples for #325: (1) python/pydynox/testing/memory.py
_apply_update_expressiontreatsSET x = list_append(...)as a silent no-op, so docs/examples/atomic/testing_atomic.py::test_atomic_append fails; (2) MemoryClient has nocount(), so docs/examples/scan/testing_scan.py::test_count_items fails with AttributeError.Follow-up on PR #571, as a separate commit: SonarCloud reports one new issue, rule python:S5778 ("Refactor this exception test to have only one invocation possibly throwing an exception") at tests/unit/test_memory_backend.py:356 in test_atomic_list_append_on_missing_attribute_raises. Build the atomic operation list (
Tagged.tags.append(["new"]),Tagged.notes.append(["note"])) before thepytest.raisesblock so onlytagged.sync_update(atomic=...)is called inside it.What Changed
SEThandling now evaluateslist_append(...)and plainif_not_exists(attr, :value)operands (nested calls work too), where before they were silently ignored. It follows DynamoDB rules:list_appendon a value that is not a list, a path to a missing attribute, an undefined:value, or an unknown function name all raiseValidationException. Updates are applied to a copy of the item, so a rejected update expression leaves the stored item unchanged.MemoryClientnow hascount()andsync_count(), built onscan(), with support for filter expressions,index_name, andconsistent_read. The memory backend support table indocs/guides/testing.mdnow listscount().tests/unit/test_memory_backend.pyfor append and prepend, nestedif_not_exists/list_append, the error cases, the unchanged-item-on-error case, and count with and without filters. In the missing-attribute test, the atomic operations are now built beforepytest.raises, so onlysync_updateruns inside it.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change is confined to the in-memory testing backend. It matches the real DynamoDBClient count signature and return shape, and the expressions that pydynox atomic operations emit for list_append and if_not_exists. Updates are now built on a copy and stored only when they succeed, which makes a rejected update leave the stored item unchanged, as DynamoDB does.
Testing
I built the extension, then ran the two docs examples. With the base memory.py both fail exactly as reported: the list_append is a silent no-op (['initial'] vs ['initial','new_tag']) and count raises AttributeError. With this change both pass. An end-user script then drove the sync and async Model APIs through append, prepend, if_not_exists, and count, plus adversarial cases. Appending to a missing attribute or a non-list raises ValidationException, and the stored item stays unchanged. I also ran the same operations against a throwaway LocalStack DynamoDB container, and every result matched the memory backend. The 9 new unit tests pass, including the Sonar-refactored one, which now calls only
sync_updateinsidepytest.raises. The full memory-backend test file and all docstesting_*.pyexamples also pass. I removed transient caches and build outputs, and the worktree is clean.Evidence: Docs examples before the fix (reproduces both reported failures)
Evidence: Docs examples after the fix (all 8 pass incl. test_atomic_append, test_count_items)
Evidence: End-user drive of MemoryBackend (sync and async, edge and error cases)
Evidence: LocalStack DynamoDB vs MemoryBackend parity table
scenario | LocalStack | MemoryBackend | match count empty | 0 | 0 | yes append+prepend | ['z','a','b'] | ['z','a','b'] | yes if_not_exists twice | 5 | 5 | yes append missing | ValidationException | ValidationException | yes status after rejected | 'active' | 'active' | yes append to string | ValidationException | ValidationException | yes count total | 2 | 2 | yes count filtered | 1 | 1 | yes ALL MATCHEvidence: New unit tests run
Evidence: Drive script source
Evidence: Parity script source
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
uv sync && uv run --with maturin maturin develop(built the Rust extension into the project venv)uv run pytest docs/examples/atomic/testing_atomic.py docs/examples/scan/testing_scan.py -vat HEADSame two failing docs tests rerun with base-commitpython/pydynox/testing/memory.pyswapped in, to reproduce the original failures, then restoredEnd-user scriptdrive_memory_backend.py: sync and async Model API underMemoryBackend()covering append, prepend, empty append, if_not_exists on missing/present, count on empty/seeded/filtered tables, and rejected updates (missing list, non-list target) checked to leave the stored item unchangedParity scriptparity_localstack.py: the same operations against real LocalStack 4.4.0 DynamoDB (testcontainers, disposable container) and against MemoryBackend, results compared side by sideuv run pytest tests/unit/test_memory_backend.py -k <9 new tests>includingtest_atomic_list_append_on_missing_attribute_raisesReadtests/unit/test_memory_backend.py:346-365to confirm onlysync_updateis insidepytest.raisesuv run pytest tests/unit/test_memory_backend.py docs/examples/**/testing_*.py -q(targeted regression for the changed update_item path)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.