Skip to content

support dataclass defaults that don't affect subsequent ORM operations #12168

@CaselIT

Description

@CaselIT

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 foo is expired it stays expired, so

thing = 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_attributes

In the above example either behaviour is fine.
Not sure if before assert thing.foo == 'bar' in the first example 'foo' should be in the expired_attributes or not. I trust your insight here if you prefer for not.
#12165 (reply in thread)

Connected discussions:

Target is 2.0.x but may be moved to 2.1 depending on the changes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions