edgedb-python
edgedb-python copied to clipboard
Correctness of distinct list and dirty state tracking
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:
- write-only mode: the collection allows
.append()and.remove()operations. Its__iter__,__len__,__contains__,__bool__raise an error "cannot access unfetched data". - 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