Allow "unsetting" ORM model fields
- Dominant language
- Python
- Stars
- 415
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
Currently we have this notion of "unset" fields in our ORM models. These can be fields that were not fetched in a query or fields that weren't initialized because they have a schema default value. In either case the fields have no value and are not intended to be passed to `save()`.
There is no mechanism that allows a user to "unset" a field once a value has been provided, though.
Consider this schema:
```edgeql
type User {
required name: str {
constraint exclusive;
}
lucky_number: int64 {
default := (100 * random())
}
}
```
The `lucky_number` is both optional and has a default value. So we can create a couple of new users:
```python
...
a = User(name='Alice')
b = User(name='Billie', lucky_number=None)
client.save(a, b)
```
Alice will have a `lucky_number` generated and Billie will have no value for that at all. However, there is no way of taking the object `b` and undoing that `lucky_number` assignment so that Billie also generates a random `lucky_number`. Once you have an object's field set to some value, there is no way to undo that short of creating a new object, but that's not always a good strategy (such as when the object has already been referenced somewhere else).
We could allow `del` to unset a field. This way if we need to modify what information we're going to pass to `save()`, we can remove fields from an object: `del b.lucky_number`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.