fix(#7): use auto-incrementing counter for item IDs - #10
fix(#7): use auto-incrementing counter for item IDs#10fullsend-ai-coder[bot] wants to merge 2 commits into
Conversation
The create_item() function generated IDs via len(_get_items()) + 1, which produced duplicate IDs after deletions reduced the list length. Replace the length-based ID with a module-level monotonically increasing counter (_next_id) that never reuses values. The reset_items() helper resets the counter for test isolation. Added test_no_id_collision_after_delete to verify that creating an item after a deletion does not produce a colliding ID. Closes #7
ReviewFindingsLow
Info
|
| _next_id = 1 | ||
|
|
||
|
|
||
| def _new_id(): |
There was a problem hiding this comment.
[low] race-condition
The _new_id() function uses a non-atomic read-increment-return on a global counter, which is not thread-safe under threaded WSGI servers. However, this is a pre-existing concern — the original len(_get_items()) + 1 was equally non-thread-safe. This PR does not regress thread safety.
Suggested fix: Use itertools.count(1) with next() for an effectively atomic counter under CPython, or protect with threading.Lock if broader runtime support is needed.
| assert resp.status_code == 404 | ||
|
|
||
|
|
||
| def test_no_id_collision_after_delete(client): |
There was a problem hiding this comment.
[low] test-adequacy
The new test validates the primary bug scenario (single delete then create) but does not cover multi-delete scenarios, which would provide stronger regression protection.
Suggested fix: Add a test that deletes multiple items then creates multiple new ones, verifying no ID collisions occur.
| assert resp.status_code == 404 | ||
|
|
||
|
|
||
| def test_no_id_collision_after_delete(client): |
There was a problem hiding this comment.
[info] test-docstring-convention
test_no_id_collision_after_delete() includes a docstring, but none of the existing 8 test functions use docstrings. Minor convention deviation.
|
/fs-fix fix low findings (race-condition and test-adequacy) feedback from the review agent |
- Replace manual global counter with itertools.count(1) for effectively atomic ID generation under CPython (addresses race-condition finding). - Add test_no_id_reuse_after_multiple_deletes to cover bulk delete+create edge case (addresses test-adequacy finding). Addresses review feedback on #10 Signed-off-by: fullsend-fix <fullsend-code@users.noreply.github.com>
🔧 Fix agent — iteration 1 (human-triggered)Addressed both low findings: replaced global counter with itertools.count for thread-safe ID generation, and added multi-delete regression test. Fixed (2):
Tests: passed Updated by fullsend fix agent |
|
/fs-review |
The create_item() function generated IDs via len(_get_items()) + 1, which produced duplicate IDs after deletions reduced the list length.
Replace the length-based ID with a module-level monotonically increasing counter (_next_id) that never reuses values. The reset_items() helper resets the counter for test isolation.
Added test_no_id_collision_after_delete to verify that creating an item after a deletion does not produce a colliding ID.
Closes #7
Post-script verification
agent/7-fix-id-collision)47f7f1511df8ad7036c082d9b2179085cd9ec107..HEAD)