edgedb-python icon indicating copy to clipboard operation
edgedb-python copied to clipboard

Correctness of distinct list and dirty state tracking

Open vpetrovykh opened this issue 5 months ago • 0 comments

We want the distinct lists to behave reasonably when created from scratch and when fetched from the database. Special care must be taken if the fetched data is incomplete or missing.

Basic ideas:

  • model.pointer = [ ... ] ALWAYS means "replace with new data"
  • model.pointer.append(...) ALWAYS translates into +=
  • model.pointer.remove(...) ALWAYS translates into -=
  • model.pointer.clear() only works when the collection is in full-mode.

There are two main modes of operation:

  1. write-only mode: the collection allows .append() and .remove() operations. Its __iter__, __len__, __contains__, __bool__ raise an error "cannot access unfetched data".
  2. full-mode: the collection allows all operations on itself.

The full-mode is used when:

  • the object is new (created from Python model)
  • a field has been fully reset on an existing object, such as by assigning []
  • a field has been explicitly fetched and thus it has a known state

The write-only mode is used when:

  • the object is initialized with an id (fetching an existing object of unknown state)
  • some field has not been explicitly fetched, thus making its state unknown

vpetrovykh avatar Jul 08 '25 10:07 vpetrovykh