-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
The use case for this is mainly dataclass defaults, so that we can use mapped_column(default=<new-constrant-here>) and that's equivalent to not setting the field at all.
This should also work for relationships:
Some considerations from other discussions:
i think one area that we have a choice to make is if you have an object with state and you say, myobject.foo = NO_VALUE - does that expire the attribute or just do nothing? I vote for the latter
#12165 (reply in thread)
I guess the behaviour wanted is
thing = session.get(Thing, 1) assert thing.foo == 'bar' thing.foo = NO_VALUE assert thing.foo == 'bar'and if
foois expired it stays expired, sothing = session.get(Thing, 1) session.expire(thing, 'foo') assert 'foo' in sa.inspect(x).expired_attributes thing.foo = NO_VALUE assert 'foo' in sa.inspect(x).expired_attributesIn the above example either behaviour is fine.
Not sure if beforeassert thing.foo == 'bar'in the first example 'foo' should be in theexpired_attributesor not. I trust your insight here if you prefer for not.
#12165 (reply in thread)
Connected discussions:
- MappedAsDataclass uses standard values as explicit... why? #12165
- SQLAlchemy2.0 + mapped_as_dataclass - how do I init only foreign key or link property? #9383
- How to directly set the value of a ForeignKey in a Dataclass mixin #9856
Target is 2.0.x but may be moved to 2.1 depending on the changes