session.save()'ed the pending item explicitly, the
attribute/collection removal still knocks it out.
+ - session.refresh() and session.expire() raise an error when
+ called on instances which are not persistent within the session
+
- Fixed potential generative bug when the same Query was used
to generate multiple Query objects using join().
``Session``.
"""
- return instance in self
+ if instance not in self:
+ raise exceptions.InvalidRequestError("Instance '%s' is not persistent within this Session" % mapperutil.instance_str(instance))
def __contains__(self, instance):
"""Return True if the given instance is associated with this session.
assert u.name == 'jack'
self.assert_sql_count(testing.db, go, 0)
+ def test_persistence_check(self):
+ mapper(User, users)
+ s = create_session()
+ u = s.get(User, 7)
+ s.clear()
+ self.assert_raises(lambda: s.expire(u), exceptions.InvalidRequestError, r"is not persistent within this Session")
+
def test_expire_doesntload_on_set(self):
mapper(User, users)
# print u._state.callables
assert u.name == 'jack'
assert id(a) not in [id(x) for x in u.addresses]
-
+
+ def test_persistence_check(self):
+ mapper(User, users)
+ s = create_session()
+ u = s.get(User, 7)
+ s.clear()
+ self.assert_raises(lambda: s.refresh(u), exceptions.InvalidRequestError, r"is not persistent within this Session")
+
def test_refresh_expired(self):
mapper(User, users)
s = create_session()
def shortDescription(self):
"""overridden to not return docstrings"""
return None
-
+
+ def assert_raises(self, callable_, except_cls, reg):
+ try:
+ callable_()
+ assert False, "Callable did not raise expected exception"
+ except Exception, e:
+ assert isinstance(e, except_cls), "Exception was not an instance of '%s' ('%s')" % (except_cls, type(e))
+ assert re.search(reg, str(e)), "Callable raised non-matching exception: '%s'" % str(e)
+
if not hasattr(unittest.TestCase, 'assertTrue'):
assertTrue = unittest.TestCase.failUnless
if not hasattr(unittest.TestCase, 'assertFalse'):
result = list(result)
print repr(result)
self.assert_list(result, class_, objects)
-
+
def assert_list(self, result, class_, list):
self.assert_(len(result) == len(list),
"result list is not the same size as test list, " +