diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-06-10 23:38:15 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-02 14:41:31 -0400 |
| commit | e28b44813721f258bf76fb7c85bf5559ecd219ec (patch) | |
| tree | 7929c90ba8d19b75ca9b33a04e8b65254ccb0899 /lib/sqlalchemy/orm/attributes.py | |
| parent | 31699bd1866bbfc36f1501e5e1b54d3c06cf3b4c (diff) | |
| download | sqlalchemy-e28b44813721f258bf76fb7c85bf5559ecd219ec.tar.gz | |
Add an init_scalar event for attributes
This allows us to build default-setting recipes such
as one that allows us to actively read column-level
defaults. An example suite is also added.
Change-Id: I7b022d52cc89526132d5bc4201ac27fea4cf088d
Fixes: #1311
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 017ad0300..7239d41f2 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -551,12 +551,13 @@ class AttributeImpl(object): def initialize(self, state, dict_): """Initialize the given state's attribute with an empty value.""" - # As of 1.0, we don't actually set a value in - # dict_. This is so that the state of the object does not get - # modified without emitting the appropriate events. + value = None + for fn in self.dispatch.init_scalar: + ret = fn(state, value, dict_) + if ret is not ATTR_EMPTY: + value = ret - - return None + return value def get(self, state, dict_, passive=PASSIVE_OFF): """Retrieve a value from the given object. |
