Skip to content

Instances that were not loaded: put() resets the version, and updates render derived attributes from them #84

Closed

Description

@fctl-sh

Priority: medium (needs a decision for the version).

  • put() of an instance that was not loaded writes version 1 (repository.py, _prepare), also in batch puts and tx.put. That contradicts "+1 on every write" and lets a stale instance pass its version check again: a stale instance loaded at v1; another writer saves (v2); put(Player(...)) writes v1; stale.save() then succeeds over both writes. Deleting and creating the item again has the same A→B→A problem, so a fix needs a decision (read the stored version, or let put() keep counting).
  • Derived attributes of updates are rendered from the wrong base. An instance that was not loaded, used as an update target, skips the read and its own values are treated as stored: players.update(Player(player_id="p1", name="Ada"), Player.score.add(10)) with a stored score of 5 stores score 15 but rank SCORE#00000010. Updates by key read the item but add no condition that it is unchanged, so a concurrent write leaves the derived attribute behind, also for versioned models, where docs/guides/single-table-design.md calls it exact (reproduced: score 26 with rank SCORE#00000025).

Found in a review of the library for bugs (fctl session); the fixes that fit in its ten pull requests are #61 to #65, #67 to #70 and #72.

Activity

  1. added
    bug
    on Oct 30, 2026
  2. fctl-sh commented on Oct 31, 2026

    @fctl-sh
    ContributorAuthor

    The second part (derived attributes rendered from the wrong base) is handled in #142: updates through an instance that was not loaded read the item, and updates that render derived attributes from a stored item require the fields they took from it unchanged, planning the update again when another writer changed them (a transaction fails instead).

    Left: the first part, the version put() of an instance that was not loaded writes. It needs a decision, which this session did not make: reading the stored version (a read per put, and still racy without a condition) or keeping the count in put() fixes the overwrite case, but not delete-and-create, which restarts at 1 whatever put() does; only a version that never repeats (a random token instead of a counter, a stored-format change) would close that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions