from .base import instance_str
from .base import LOAD_AGAINST_COMMITTED
from .base import manager_of_class
-from .base import NEVER_SET
+from .base import NEVER_SET # noqa
from .base import NO_AUTOFLUSH
from .base import NO_CHANGE # noqa
from .base import NO_RAISE
from .base import PASSIVE_NO_RESULT
from .base import PASSIVE_OFF
from .base import PASSIVE_ONLY_PERSISTENT
-from .base import PASSIVE_RETURN_NEVER_SET
+from .base import PASSIVE_RETURN_NO_VALUE
from .base import RELATED_OBJECT_OK # noqa
from .base import SQL_OK # noqa
from .base import state_str
key = self.key
if (
key not in state.committed_state
- or state.committed_state[key] is NEVER_SET
+ or state.committed_state[key] is NO_VALUE
):
if not passive & CALLABLES_OK:
return PASSIVE_NO_RESULT
else:
value = ATTR_EMPTY
- if value is PASSIVE_NO_RESULT or value is NEVER_SET:
+ if value is PASSIVE_NO_RESULT or value is NO_VALUE:
return value
elif value is ATTR_WAS_SET:
try:
return self.set_committed_value(state, dict_, value)
if not passive & INIT_OK:
- return NEVER_SET
+ return NO_VALUE
else:
# Return a new, empty value
return self.initialize(state, dict_)
if self.key in state.committed_state:
value = state.committed_state[self.key]
- if value in (NO_VALUE, NEVER_SET):
+ if value is NO_VALUE:
return None
else:
return value
def delete(self, state, dict_):
if self.dispatch._active_history:
- old = self.get(state, dict_, PASSIVE_RETURN_NEVER_SET)
+ old = self.get(state, dict_, PASSIVE_RETURN_NO_VALUE)
else:
old = dict_.get(self.key, NO_VALUE)
def get_history(self, state, dict_, passive=PASSIVE_OFF):
if self.key in dict_:
return History.from_scalar_attribute(self, state, dict_[self.key])
+ elif self.key in state.committed_state:
+ return History.from_scalar_attribute(self, state, NO_VALUE)
else:
if passive & INIT_OK:
passive ^= INIT_OK
pop=False,
):
if self.dispatch._active_history:
- old = self.get(state, dict_, PASSIVE_RETURN_NEVER_SET)
+ old = self.get(state, dict_, PASSIVE_RETURN_NO_VALUE)
else:
old = dict_.get(self.key, NO_VALUE)
if (
current is not None
and current is not PASSIVE_NO_RESULT
- and current is not NEVER_SET
+ and current is not NO_VALUE
):
ret = [(instance_state(current), current)]
else:
if (
original is not None
and original is not PASSIVE_NO_RESULT
- and original is not NEVER_SET
+ and original is not NO_VALUE
and original is not current
):
if previous is not value and previous not in (
None,
PASSIVE_NO_RESULT,
- NEVER_SET,
+ NO_VALUE,
):
self.sethasparent(instance_state(previous), state, False)
if self.key in state.committed_state:
original = state.committed_state[self.key]
- if original not in (NO_VALUE, NEVER_SET):
+ if original is not NO_VALUE:
current_states = [
((c is not None) and instance_state(c) or None, c)
for c in current
for fn in self.dispatch.append:
value = fn(state, value, initiator or self._append_token)
- state._modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NO_VALUE, True)
if self.trackparent and value is not None:
self.sethasparent(instance_state(value), state, True)
operations (even though set.pop is the one where it is really needed).
"""
- state._modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NO_VALUE, True)
def fire_remove_event(self, state, dict_, value, initiator):
if self.trackparent and value is not None:
for fn in self.dispatch.remove:
fn(state, value, initiator or self._remove_token)
- state._modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NO_VALUE, True)
def delete(self, state, dict_):
if self.key not in dict_:
return
- state._modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NO_VALUE, True)
collection = self.get_collection(state, state.dict)
collection.clear_with_event()
if (
oldchild is not None
and oldchild is not PASSIVE_NO_RESULT
- and oldchild is not NEVER_SET
+ and oldchild is not NO_VALUE
):
# With lazy=None, there's no guarantee that the full collection is
# present when updating via a backref.
if (
child is not None
and child is not PASSIVE_NO_RESULT
- and child is not NEVER_SET
+ and child is not NO_VALUE
):
child_state, child_dict = (
instance_state(child),
_NO_HISTORY = util.symbol("NO_HISTORY")
-_NO_STATE_SYMBOLS = frozenset(
- [id(PASSIVE_NO_RESULT), id(NO_VALUE), id(NEVER_SET)]
-)
+_NO_STATE_SYMBOLS = frozenset([id(PASSIVE_NO_RESULT), id(NO_VALUE)])
History = util.namedtuple("History", ["added", "unchanged", "deleted"])
original = state.committed_state.get(attribute.key, _NO_HISTORY)
if original is _NO_HISTORY:
- if current is NEVER_SET:
+ if current is NO_VALUE:
return cls((), (), ())
else:
return cls((), [current], ())
# don't let ClauseElement expressions here trip things up
- elif attribute.is_equal(current, original) is True:
+ elif (
+ current is not NO_VALUE
+ and attribute.is_equal(current, original) is True
+ ):
return cls((), [current], ())
else:
# current convention on native scalars is to not
current = None
else:
deleted = [original]
- if current is NEVER_SET:
+ if current is NO_VALUE:
return cls((), (), deleted)
else:
return cls([current], (), deleted)
original = state.committed_state.get(attribute.key, _NO_HISTORY)
if original is _NO_HISTORY:
- if current is NO_VALUE or current is NEVER_SET:
+ if current is NO_VALUE:
return cls((), (), ())
else:
return cls((), [current], ())
- elif current is original and current is not NEVER_SET:
+ elif current is original and current is not NO_VALUE:
return cls((), [current], ())
else:
# current convention on related objects is to not
current = None
else:
deleted = [original]
- if current is NO_VALUE or current is NEVER_SET:
+ if current is NO_VALUE:
return cls((), (), deleted)
else:
return cls([current], (), deleted)
def from_collection(cls, attribute, state, current):
original = state.committed_state.get(attribute.key, _NO_HISTORY)
- if current is NO_VALUE or current is NEVER_SET:
+ if current is NO_VALUE:
return cls((), (), ())
current = getattr(current, "_sa_adapter")
- if original in (NO_VALUE, NEVER_SET):
+ if original is NO_VALUE:
return cls(list(current), (), ())
elif original is _NO_HISTORY:
return cls((), list(current), ())
attributes.PASSIVE_NO_RESULT,
)
- def test_passive_no_result_never_set(self):
- attr, state, dict_ = self._fixture(attributes.NEVER_SET)
+ def test_passive_no_result_no_value(self):
+ attr, state, dict_ = self._fixture(attributes.NO_VALUE)
eq_(
attr.get(state, dict_, passive=attributes.PASSIVE_NO_INITIALIZE),
attributes.PASSIVE_NO_RESULT,
)
assert "attr" not in dict_
- def test_passive_ret_never_set_never_set(self):
- attr, state, dict_ = self._fixture(attributes.NEVER_SET)
+ def test_passive_ret_no_value(self):
+ attr, state, dict_ = self._fixture(attributes.NO_VALUE)
eq_(
- attr.get(
- state, dict_, passive=attributes.PASSIVE_RETURN_NEVER_SET
- ),
- attributes.NEVER_SET,
+ attr.get(state, dict_, passive=attributes.PASSIVE_RETURN_NO_VALUE),
+ attributes.NO_VALUE,
)
assert "attr" not in dict_
- def test_passive_ret_never_set_empty(self):
+ def test_passive_ret_no_value_empty(self):
attr, state, dict_ = self._fixture(None)
eq_(
- attr.get(
- state, dict_, passive=attributes.PASSIVE_RETURN_NEVER_SET
- ),
- attributes.NEVER_SET,
+ attr.get(state, dict_, passive=attributes.PASSIVE_RETURN_NO_VALUE),
+ attributes.NO_VALUE,
)
assert "attr" not in dict_
)
eq_(lazy_posts.call_count, 1)
- def test_passive_history_collection_never_set(self):
+ def test_passive_history_collection_no_value(self):
Post, Blog, lazy_posts = self._fixture()
lazy_posts.return_value = attributes.PASSIVE_NO_RESULT
attributes.instance_dict(b),
)
- # this sets up NEVER_SET on b.posts
+ # this sets up NO_VALUE on b.posts
p.blog = b
- eq_(state.committed_state, {"posts": attributes.NEVER_SET})
+ eq_(state.committed_state, {"posts": attributes.NO_VALUE})
assert "posts" not in dict_
# then suppose the object was made transient again,
p2 = Post("asdf")
p2.blog = b
- eq_(state.committed_state, {"posts": attributes.NEVER_SET})
+ eq_(state.committed_state, {"posts": attributes.NO_VALUE})
eq_(dict_["posts"], [p2])
# then this would fail.
assert "someattr" not in f.__dict__
assert "someattr" not in attributes.instance_state(f).committed_state
- def test_collection_never_set(self):
+ def test_collection_no_value(self):
Foo = self._fixture(uselist=True, useobject=True, active_history=True)
f = Foo()
eq_(self._someattr_history(f, passive=True), (None, None, None))
- def test_scalar_obj_never_set(self):
+ def test_scalar_obj_no_value(self):
Foo = self._fixture(uselist=False, useobject=True, active_history=True)
f = Foo()
eq_(self._someattr_history(f, passive=True), (None, None, None))
- def test_scalar_never_set(self):
+ def test_scalar_no_value(self):
Foo = self._fixture(
uselist=False, useobject=False, active_history=True
)
b = B()
b.attrib = "foo"
eq_(b.attrib, "foo")
- eq_(canary, [("foo", attributes.NEVER_SET)])
+ eq_(canary, [("foo", attributes.NO_VALUE)])
c = C()
c.attrib = "bar"
eq_(c.attrib, "bar")
eq_(
canary,
- [("foo", attributes.NEVER_SET), ("bar", attributes.NEVER_SET)],
+ [("foo", attributes.NO_VALUE), ("bar", attributes.NO_VALUE)],
)
def test_propagate(self):
d1 = D()
b.attrib = d1
is_(b.attrib, d1)
- eq_(canary, [(d1, attributes.NEVER_SET)])
+ eq_(canary, [(d1, attributes.NO_VALUE)])
c = C()
d2 = D()
c.attrib = d2
is_(c.attrib, d2)
- eq_(
- canary,
- [(d1, attributes.NEVER_SET), (d2, attributes.NEVER_SET)],
- )
+ eq_(canary, [(d1, attributes.NO_VALUE), (d2, attributes.NO_VALUE)])
def _test_propagate_fixtures(self, active_history, useobject):
classes = [None, None, None, None]