Skip to content

ObjectState stores derived facts and refreshes them by hand; every copier lists its fields #37

Open

Description

@trissim

All line numbers are at main 1fcdf12.

Problem

ObjectState (2,736 lines) keeps its state in about 22 separate private attributes. Three kinds of fact are mixed together:

  1. what the user set: parameters, _saved_parameters;
  2. what follows from that and the context: _live_resolved, _saved_resolved, _live_provenance, _invalid_fields;
  3. what follows from comparing those: _dirty_fields, _signature_diff_fields, _raw_dirty, and the _last_changed_* group.

Because kinds 2 and 3 are stored, they must be refreshed by hand. _sync_materialized_state (object_state.py:2016) says so in its docstring: "Call this after ANY mutation that could affect ...". It has 11 callers (8 in object_state.py, 3 in object_state_registry.py). A mutation path that forgets the call leaves the dirty markers wrong, and nothing detects it.

Because the state is spread over many attributes, everything that copies it has to list them:

  • ObjectStateTransactionCheckpoint (transaction_checkpoint.py) declares 23 fields mirroring them, and capture and restore each assign them one by one (:77-94, :124-145).
  • StateSnapshot.from_dict, mark_saved (144 lines) and _restore_saved_impl do the same for their subsets.

Adding one field to ObjectState means editing each of these.

Wanted

ObjectState holds one value object for kind 1 (the authored state) and derives kinds 2 and 3 from it and the context, cached against that value so no caller has to request a refresh. The previous value is kept only as long as needed to compute which paths changed for notifications. A checkpoint is then a reference to the value object, not a field-by-field copy.

This is the largest change in the list and should follow the resolver issue (#29), since both touch how resolved values are produced.

Acceptance

_sync_materialized_state has no external callers, or is gone. ObjectStateTransactionCheckpoint has no field that mirrors an ObjectState attribute one to one. Adding a new authored field needs an edit in one place. The undo/redo, restore and notification tests pass unchanged.

The function sizes are a symptom of the same thing and should shrink with it: update_parameter 185 lines, __init__ 151, mark_saved 144, to_object 135, _recompute_invalid_fields 124; in the registry _record_snapshot_internal 157.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions