diff options
41 files changed, 514 insertions, 506 deletions
@@ -11,7 +11,12 @@ CHANGES - Removed an internal join cache which could potentially leak memory when issuing query.join() repeatedly to ad-hoc selectables. - + + - The "clear()", "save()", "update()", "save_or_update()" + Session methods have been deprecated, replaced by + "expunge_all()" and "add()". "expunge_all()" has also + been added to ScopedSession. + - Modernized the "no mapped table" exception and added a more explicit __table__/__tablename__ exception to declarative. diff --git a/lib/sqlalchemy/ext/sqlsoup.py b/lib/sqlalchemy/ext/sqlsoup.py index fbbf8d6fd..37b9d8fa8 100644 --- a/lib/sqlalchemy/ext/sqlsoup.py +++ b/lib/sqlalchemy/ext/sqlsoup.py @@ -316,7 +316,7 @@ Boring tests here. Nothing of real expository value. >>> db.loans.count() 1 >>> _ = db.loans.insert(book_id=1, user_name='Bhargan Basepair') - >>> db.clear() + >>> db.expunge_all() >>> db.flush() >>> db.loans.count() 1 @@ -516,7 +516,10 @@ class SqlSoup: Session.flush() def clear(self): - Session.clear() + Session.expunge_all() + + def expunge_all(self): + Session.expunge_all() def map(self, selectable, **kwargs): try: diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 62f2d8f31..690286e9b 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -526,7 +526,7 @@ class Session(object): public_methods = ( '__contains__', '__iter__', 'add', 'add_all', 'begin', 'begin_nested', 'clear', 'close', 'commit', 'connection', 'delete', 'execute', 'expire', - 'expire_all', 'expunge', 'flush', 'get_bind', 'is_modified', + 'expire_all', 'expunge', 'expunge_all', 'flush', 'get_bind', 'is_modified', 'merge', 'query', 'refresh', 'rollback', 'save', 'save_or_update', 'scalar', 'update') @@ -772,17 +772,17 @@ class Session(object): not use any connection resources until they are first needed. """ - self.clear() + self.expunge_all() if self.transaction is not None: for transaction in self.transaction._iterate_parents(): transaction.close() + @classmethod def close_all(cls): """Close *all* sessions in memory.""" for sess in _sessions.values(): sess.close() - close_all = classmethod(close_all) def expunge_all(self): """Remove all object instances from this ``Session``. @@ -797,10 +797,8 @@ class Session(object): self.identity_map = self._identity_cls() self._new = {} self._deleted = {} - clear = expunge_all - # TODO: deprecate - #clear = util.deprecated()(expunge_all) + clear = util.deprecated("Use session.expunge_all()")(expunge_all) # TODO: need much more test coverage for bind_mapper() and similar ! # TODO: + crystalize + document resolution order vis. bind_mapper/bind_table @@ -1044,7 +1042,7 @@ class Session(object): self.identity_map.discard(state) self._deleted.pop(state, None) - @util.pending_deprecation('0.5.x', "Use session.add()") + @util.deprecated("Use session.add()") def save(self, instance): """Add a transient (unsaved) instance to this ``Session``. @@ -1063,7 +1061,7 @@ class Session(object): state = _state_for_unsaved_instance(instance, create=True) self._save_impl(state) - @util.pending_deprecation('0.5.x', "Use session.add()") + @util.deprecated("Use session.add()") def update(self, instance): """Bring a detached (saved) instance into this ``Session``. @@ -1106,7 +1104,7 @@ class Session(object): self._cascade_save_or_update(state) save_or_update = ( - util.pending_deprecation('0.5.x', "Use session.add()")(add)) + util.deprecated("Use session.add()")(add)) def _cascade_save_or_update(self, state): for state, mapper in _cascade_unknown_state_iterator('save-update', state, halt_on=lambda c:c in self): @@ -1205,7 +1203,7 @@ class Session(object): merged = mapper.class_manager.new_instance() merged_state = attributes.instance_state(merged) new_instance = True - self.save(merged) + self.add(merged) _recursive[instance] = merged diff --git a/test/ext/associationproxy.py b/test/ext/associationproxy.py index 40d36a67a..821ed9072 100644 --- a/test/ext/associationproxy.py +++ b/test/ext/associationproxy.py @@ -82,10 +82,10 @@ class _CollectionOperations(TestBase): def roundtrip(self, obj): if obj not in self.session: - self.session.save(obj) + self.session.add(obj) self.session.flush() id, type_ = obj.id, type(obj) - self.session.clear() + self.session.expunge_all() return self.session.query(type_).get(id) def _test_sequence_ops(self): @@ -636,10 +636,10 @@ class ScalarTest(TestBase): def roundtrip(obj): if obj not in session: - session.save(obj) + session.add(obj) session.flush() id, type_ = obj.id, type(obj) - session.clear() + session.expunge_all() return session.query(type_).get(id) p = Parent('p') @@ -752,10 +752,10 @@ class LazyLoadTest(TestBase): self.metadata.drop_all() def roundtrip(self, obj): - self.session.save(obj) + self.session.add(obj) self.session.flush() id, type_ = obj.id, type(obj) - self.session.clear() + self.session.expunge_all() return self.session.query(type_).get(id) def test_lazy_list(self): diff --git a/test/ext/declarative.py b/test/ext/declarative.py index c9477b5d8..b10654d6c 100644 --- a/test/ext/declarative.py +++ b/test/ext/declarative.py @@ -47,7 +47,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', addresses=[ Address(email='one'), @@ -131,7 +131,7 @@ class DeclarativeTest(DeclarativeTestBase): u1 = User(name='ed', addresses=[Address(email='abc'), Address(email='def'), Address(email='xyz')]) sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(User).filter(User.name == 'ed').one(), User(name='ed', addresses=[Address(email='xyz'), Address(email='def'), Address(email='abc')]) ) @@ -193,7 +193,7 @@ class DeclarativeTest(DeclarativeTestBase): u1 = User(name='ed', addresses=[Address(email='abc'), Address(email='xyz'), Address(email='def')]) sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(User).filter(User.name == 'ed').one(), User(name='ed', addresses=[Address(email='abc'), Address(email='def'), Address(email='xyz')]) ) @@ -282,7 +282,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', addresses=[ Address(email='one'), @@ -316,7 +316,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).options(eagerload(User.addresses)).all(), [User(name='u1', addresses=[ Address(email='one'), Address(email='two'), @@ -345,7 +345,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() u = sess.query(User).filter(User.name == 'u1').one() a = u.addresses @@ -376,7 +376,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', addresses=[ Address(email='one'), @@ -477,7 +477,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', address_count=2, addresses=[ @@ -502,7 +502,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', a='a', b='b')]) @@ -533,7 +533,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', adr_count=2, addresses=[ @@ -570,7 +570,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(User(name='u1')) sess.flush() - sess.clear() + sess.expunge_all() u1 = sess.query(User).filter(User.name == 'u1').one() assert 'name' not in u1.__dict__ @@ -673,7 +673,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', addresses=[ Address(email='one'), @@ -709,7 +709,7 @@ class DeclarativeTest(DeclarativeTestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', address_count=2, addresses=[ @@ -812,7 +812,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): sess.add(c1) sess.add(c2) sess.flush() - sess.clear() + sess.expunge_all() eq_((sess.query(Company). filter(Company.employees.of_type(Engineer). @@ -827,11 +827,11 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): # assert that the "id" column is available without a second load. # this would be the symptom of the previous step not being correct. - sess.clear() + sess.expunge_all() def go(): assert sess.query(Manager).filter(Manager.name=='dogbert').one().id self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): assert sess.query(Person).filter(Manager.name=='dogbert').one().id self.assert_sql_count(testing.db, go, 1) @@ -902,7 +902,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): sess.add(c1) sess.add(c2) sess.flush() - sess.clear() + sess.expunge_all() eq_((sess.query(Person). filter(Engineer.primary_language == 'cobol').first()), @@ -973,7 +973,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): sess.add(c1) sess.add(c2) sess.flush() - sess.clear() + sess.expunge_all() eq_((sess.query(Person). filter(Engineer.primary_language == 'cobol').first()), @@ -1036,7 +1036,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): sess.add(c1) sess.add(c2) sess.flush() - sess.clear() + sess.expunge_all() eq_((sess.query(Person).with_polymorphic(Engineer). filter(Engineer.primary_language == 'cobol').first()), @@ -1085,7 +1085,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): e3 =Engineer(name="vlad", primary_language=cobol) sess.add_all([e1, e2, e3]) sess.flush() - sess.clear() + sess.expunge_all() eq_((sess.query(Person). filter(Engineer.primary_language.has(Language.name=='cobol')).first()), @@ -1204,7 +1204,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): sess.add_all([e1, e2, m1, e3]) sess.flush() - sess.clear() + sess.expunge_all() eq_( sess.query(Person).order_by(Person.name).all(), [ @@ -1338,7 +1338,7 @@ class DeclarativeReflectionTest(testing.TestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', addresses=[ Address(email='one'), @@ -1369,7 +1369,7 @@ class DeclarativeReflectionTest(testing.TestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(nom='u1', addresses=[ Address(email='one'), @@ -1403,7 +1403,7 @@ class DeclarativeReflectionTest(testing.TestBase): sess = create_session() sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).all(), [User(name='u1', handles=[ IMHandle(network='blabber', handle='foo'), @@ -1468,11 +1468,11 @@ class DeclarativeReflectionTest(testing.TestBase): eq_(u1.uc_name, 'SOMEUSER', u1.uc_name) sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() rt = sess.query(User).filter(User.uc_name == 'SOMEUSER').one() eq_(rt, u1) - sess.clear() + sess.expunge_all() rt = sess.query(User).filter(User.uc_name.startswith('SOMEUSE')).one() eq_(rt, u1) diff --git a/test/ext/orderinglist.py b/test/ext/orderinglist.py index 4ff03408f..c111a02de 100644 --- a/test/ext/orderinglist.py +++ b/test/ext/orderinglist.py @@ -132,11 +132,11 @@ class OrderingListTest(TestBase): self.assert_(s1.bullets[3].position == 4) session = create_session() - session.save(s1) + session.add(s1) session.flush() id = s1.id - session.clear() + session.expunge_all() del s1 srt = session.query(Slide).get(id) @@ -196,11 +196,11 @@ class OrderingListTest(TestBase): s1.bullets._reorder() self.assert_(s1.bullets[4].position == 5) session = create_session() - session.save(s1) + session.add(s1) session.flush() id = s1.id - session.clear() + session.expunge_all() del s1 srt = session.query(Slide).get(id) @@ -215,7 +215,7 @@ class OrderingListTest(TestBase): srt.bullets._raw_append(Bullet('raw2')) srt.bullets[-1].position = 6 session.flush() - session.clear() + session.expunge_all() srt = session.query(Slide).get(id) titles = ['s1/b1','s1/b2','s1/b100','s1/b4', 'raw', 'raw2'] @@ -253,11 +253,11 @@ class OrderingListTest(TestBase): self.assert_(s1.bullets[5].position == 5) session = create_session() - session.save(s1) + session.add(s1) session.flush() id = s1.id - session.clear() + session.expunge_all() del s1 srt = session.query(Slide).get(id) @@ -296,11 +296,11 @@ class OrderingListTest(TestBase): self.assert_(s1.bullets[li] == b[bi]) session = create_session() - session.save(s1) + session.add(s1) session.flush() id = s1.id - session.clear() + session.expunge_all() del s1 srt = session.query(Slide).get(id) @@ -323,7 +323,7 @@ class OrderingListTest(TestBase): self.assert_(s1.bullets[2].position == 2) session = create_session() - session.save(s1) + session.add(s1) session.flush() new_bullet = Bullet('new 2') @@ -339,7 +339,7 @@ class OrderingListTest(TestBase): id = s1.id session.flush() - session.clear() + session.expunge_all() srt = session.query(Slide).get(id) diff --git a/test/orm/association.py b/test/orm/association.py index 59130aac2..d9265ffb1 100644 --- a/test/orm/association.py +++ b/test/orm/association.py @@ -72,7 +72,7 @@ class AssociationTest(_base.MappedTest): sess.add_all((item1, item2)) sess.flush() saved = repr([item1, item2]) - sess.clear() + sess.expunge_all() l = sess.query(Item).all() loaded = repr(l) eq_(saved, loaded) @@ -91,7 +91,7 @@ class AssociationTest(_base.MappedTest): item1.keywords.append(KeywordAssociation(red_keyword, 'new_red_assoc')) sess.flush() saved = repr([item1]) - sess.clear() + sess.expunge_all() l = sess.query(Item).all() loaded = repr(l) eq_(saved, loaded) @@ -118,7 +118,7 @@ class AssociationTest(_base.MappedTest): sess.flush() saved = repr([item1, item2]) - sess.clear() + sess.expunge_all() l = sess.query(Item).all() loaded = repr(l) eq_(saved, loaded) diff --git a/test/orm/assorted_eager.py b/test/orm/assorted_eager.py index c6444a333..8dc95fa5b 100644 --- a/test/orm/assorted_eager.py +++ b/test/orm/assorted_eager.py @@ -260,7 +260,7 @@ class EagerTest2(_base.MappedTest): session = create_session() session.add(p) session.flush() - session.clear() + session.expunge_all() obj = session.query(Left).filter_by(data='l1').one() @@ -463,13 +463,13 @@ class EagerTest5(_base.MappedTest): d2.comments = [Comment('uid2', 'comment')] sess.add_all((d, d2)) sess.flush() - sess.clear() + sess.expunge_all() # this eager load sets up an AliasedClauses for the "comment" # relationship, then stores it in clauses_by_lead_mapper[mapper for # Derived] d = sess.query(Derived).get('uid1') - sess.clear() + sess.expunge_all() assert len([c for c in d.comments]) == 1 # this eager load sets up an AliasedClauses for the "comment" @@ -477,7 +477,7 @@ class EagerTest5(_base.MappedTest): # for DerivedII]. the bug was that the previous AliasedClause create # prevented this population from occurring. d2 = sess.query(DerivedII).get('uid2') - sess.clear() + sess.expunge_all() # object is not in the session; therefore the lazy load cant trigger # here, eager load had to succeed @@ -546,7 +546,7 @@ class EagerTest6(_base.MappedTest): sess = create_session() sess.add(d) sess.flush() - sess.clear() + sess.expunge_all() x = sess.query(Design).get(1) x.inheritedParts @@ -630,10 +630,10 @@ class EagerTest7(_base.MappedTest): company_id = c1.company_id invoice_id = i1.invoice_id - session.clear() + session.expunge_all() c = session.query(Company).get(company_id) - session.clear() + session.expunge_all() i = session.query(Invoice).get(invoice_id) eq_(c, i.company) @@ -674,7 +674,7 @@ class EagerTest7(_base.MappedTest): company_id = c1.company_id - session.clear() + session.expunge_all() a = session.query(Company).get(company_id) @@ -688,10 +688,10 @@ class EagerTest7(_base.MappedTest): session.flush() invoice_id = i1.invoice_id - session.clear() + session.expunge_all() c = session.query(Company).get(company_id) - session.clear() + session.expunge_all() i = session.query(Invoice).get(invoice_id) eq_(c, i.company) @@ -849,7 +849,7 @@ class EagerTest9(_base.MappedTest): session.add(acc1) session.flush() - session.clear() + session.expunge_all() def go(): # load just the first Account. eager loading will actually load diff --git a/test/orm/bind.py b/test/orm/bind.py index 189b864c0..33d028d22 100644 --- a/test/orm/bind.py +++ b/test/orm/bind.py @@ -33,7 +33,7 @@ class BindTest(_base.MappedTest): sess = create_session(bind=bind) assert sess.bind is bind f = Foo() - sess.save(f) + sess.add(f) sess.flush() assert sess.query(Foo).get(f.id) is f finally: diff --git a/test/orm/cascade.py b/test/orm/cascade.py index 3bf7913e4..10de5cce7 100644 --- a/test/orm/cascade.py +++ b/test/orm/cascade.py @@ -31,7 +31,7 @@ class O2MCascadeTest(_fixtures.FixtureTest): Order(description='someotherorder')]) sess.add(u) sess.flush() - sess.clear() + sess.expunge_all() u = sess.query(User).get(u.id) eq_(u, User(name='jack', @@ -40,7 +40,7 @@ class O2MCascadeTest(_fixtures.FixtureTest): u.orders=[Order(description="order 3"), Order(description="order 4")] sess.flush() - sess.clear() + sess.expunge_all() u = sess.query(User).get(u.id) eq_(u, User(name='jack', @@ -82,7 +82,7 @@ class O2MCascadeTest(_fixtures.FixtureTest): Address(email_address="address2")]) sess.add(u) sess.flush() - sess.clear() + sess.expunge_all() assert addresses.count().scalar() == 2 assert users.count().scalar() == 1 @@ -116,7 +116,7 @@ class O2MCascadeTest(_fixtures.FixtureTest): u2 = User(name='newuser', orders=[o]) sess.add(u2) sess.flush() - sess.clear() + sess.expunge_all() assert users.count().scalar() == 1 assert orders.count().scalar() == 1 eq_(sess.query(User).all(), @@ -231,7 +231,7 @@ class NoSaveCascadeTest(_fixtures.FixtureTest): assert u1 not in sess assert o1 in sess - sess.clear() + sess.expunge_all() o1 = Order() u1 = User(orders=[o1]) @@ -255,7 +255,7 @@ class NoSaveCascadeTest(_fixtures.FixtureTest): assert o1 not in sess assert u1 in sess - sess.clear() + sess.expunge_all() u1 = User() o1 = Order() @@ -280,7 +280,7 @@ class NoSaveCascadeTest(_fixtures.FixtureTest): assert i1 in sess assert k1 not in sess - sess.clear() + sess.expunge_all() i1 = Item() k1 = Keyword() @@ -383,12 +383,12 @@ class M2OCascadeTest(_base.MappedTest): jack = sess.query(User).filter_by(name="jack").one() p = jack.pref e = jack.pref.extra[0] - sess.clear() + sess.expunge_all() jack.pref = None - sess.update(jack) - sess.update(p) - sess.update(e) + sess.add(jack) + sess.add(p) + sess.add(e) assert p in sess assert e in sess sess.flush() @@ -840,7 +840,7 @@ class UnsavedOrphansTest(_base.MappedTest): u.addresses.remove(a1) assert a1 in s s.flush() - s.clear() + s.expunge_all() eq_(s.query(Address).all(), [Address(email_address='ad1')]) @@ -1008,7 +1008,7 @@ class DoubleParentOrphanTest(_base.MappedTest): b1 = Business(description='business1', address=Address(street='address2')) session.add_all((h1,b1)) session.flush() - session.clear() + session.expunge_all() eq_(session.query(Home).get(h1.id), Home(description='home1', address=Address(street='address1'))) eq_(session.query(Business).get(b1.id), Business(description='business1', address=Address(street='address2'))) @@ -1066,7 +1066,7 @@ class CollectionAssignmentOrphanTest(_base.MappedTest): sess.add(a1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(A).get(a1.id), A(name='a1', bs=[B(name='b1'), B(name='b2'), B(name='b3')])) @@ -1078,7 +1078,7 @@ class CollectionAssignmentOrphanTest(_base.MappedTest): a1.bs[1].foo='b3modified' sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(A).get(a1.id), A(name='a1', bs=[B(name='b1'), B(name='b2'), B(name='b3')])) diff --git a/test/orm/collection.py b/test/orm/collection.py index 2c69f65e7..23f643597 100644 --- a/test/orm/collection.py +++ b/test/orm/collection.py @@ -1373,7 +1373,7 @@ class DictHelpersTest(_base.MappedTest): session.add(p) session.flush() pid = p.id - session.clear() + session.expunge_all() p = session.query(Parent).get(pid) @@ -1385,7 +1385,7 @@ class DictHelpersTest(_base.MappedTest): Child('foo', 'newvalue')) session.flush() - session.clear() + session.expunge_all() p = session.query(Parent).get(pid) @@ -1394,7 +1394,7 @@ class DictHelpersTest(_base.MappedTest): self.assert_(len(list(collections.collection_adapter(p.children))) == 2) session.flush() - session.clear() + session.expunge_all() p = session.query(Parent).get(pid) self.assert_(len(list(collections.collection_adapter(p.children))) == 2) @@ -1404,7 +1404,7 @@ class DictHelpersTest(_base.MappedTest): self.assert_(len(list(collections.collection_adapter(p.children))) == 1) session.flush() - session.clear() + session.expunge_all() p = session.query(Parent).get(pid) self.assert_(len(list(collections.collection_adapter(p.children))) == 1) @@ -1412,7 +1412,7 @@ class DictHelpersTest(_base.MappedTest): del p.children['bar'] self.assert_(len(list(collections.collection_adapter(p.children))) == 0) session.flush() - session.clear() + session.expunge_all() p = session.query(Parent).get(pid) self.assert_(len(list(collections.collection_adapter(p.children))) == 0) @@ -1434,7 +1434,7 @@ class DictHelpersTest(_base.MappedTest): session.add(p) session.flush() pid = p.id - session.clear() + session.expunge_all() p = session.query(Parent).get(pid) @@ -1445,7 +1445,7 @@ class DictHelpersTest(_base.MappedTest): Child('foo', '1', 'newvalue')) session.flush() - session.clear() + session.expunge_all() p = session.query(Parent).get(pid) @@ -1562,7 +1562,7 @@ class CustomCollectionsTest(_base.MappedTest): sess = create_session() sess.add(f) sess.flush() - sess.clear() + sess.expunge_all() f = sess.query(Foo).get(f.col1) assert len(list(f.bars)) == 2 f.bars.clear() @@ -1594,7 +1594,7 @@ class CustomCollectionsTest(_base.MappedTest): sess = create_session() sess.add(f) sess.flush() - sess.clear() + sess.expunge_all() f = sess.query(Foo).get(f.col1) assert len(list(f.bars)) == 2 f.bars.clear() @@ -1622,7 +1622,7 @@ class CustomCollectionsTest(_base.MappedTest): sess = create_session() sess.add(f) sess.flush() - sess.clear() + sess.expunge_all() f = sess.query(Foo).get(f.col1) assert len(list(f.bars)) == 2 @@ -1632,7 +1632,7 @@ class CustomCollectionsTest(_base.MappedTest): col.append_with_event(Bar('b')) f.bars['a'] = Bar('a') sess.flush() - sess.clear() + sess.expunge_all() f = sess.query(Foo).get(f.col1) assert len(list(f.bars)) == 2 @@ -1807,7 +1807,7 @@ class CustomCollectionsTest(_base.MappedTest): sess = create_session() sess.add(p1) sess.flush() - sess.clear() + sess.expunge_all() p2 = sess.query(Parent).get(p1.col1) o = list(p2.children) diff --git a/test/orm/cycles.py b/test/orm/cycles.py index c50633c01..958afadaf 100644 --- a/test/orm/cycles.py +++ b/test/orm/cycles.py @@ -80,7 +80,7 @@ class SelfReferentialTest(_base.MappedTest): sess = create_session() sess.add(c1) sess.flush() - sess.clear() + sess.expunge_all() c1 = sess.query(C1).get(c1.c1) c2 = C1() c2.parent = c1 @@ -141,7 +141,7 @@ class SelfReferentialNoPKTest(_base.MappedTest): s = create_session() s.add(t1) s.flush() - s.clear() + s.expunge_all() t = s.query(TT).filter_by(id=t1.id).one() eq_(t.children[0].parent_uuid, t1.uuid) @@ -153,7 +153,7 @@ class SelfReferentialNoPKTest(_base.MappedTest): t1.children.append(t2) s.add(t1) s.flush() - s.clear() + s.expunge_all() t = s.query(TT).filter_by(id=t2.id).one() eq_(t.uuid, t2.uuid) @@ -207,7 +207,7 @@ class InheritTestOne(_base.MappedTest): c1.child1_data = "qwerty" session.add(c1) session.flush() - session.clear() + session.expunge_all() c1 = session.query(Child1).filter_by(child1_data="qwerty").one() c2 = Child2() @@ -831,7 +831,7 @@ class SelfReferentialPostUpdateTest2(_base.MappedTest): # to fire off anyway session.add(f2) session.flush() - session.clear() + session.expunge_all() f1 = session.query(A).get(f1.id) f2 = session.query(A).get(f2.id) diff --git a/test/orm/dynamic.py b/test/orm/dynamic.py index 010999ac5..e72acac9a 100644 --- a/test/orm/dynamic.py +++ b/test/orm/dynamic.py @@ -171,7 +171,7 @@ class FlushTest(_fixtures.FixtureTest): from sqlalchemy.orm import attributes self.assertEquals(attributes.get_history(attributes.instance_state(u1), 'addresses'), ([], [Address(email_address='lala@hoho.com')], [])) - sess.clear() + sess.expunge_all() # test the test fixture a little bit assert User(name='jack', addresses=[Address(email_address='wrong')]) != sess.query(User).first() @@ -231,7 +231,7 @@ class FlushTest(_fixtures.FixtureTest): sess.delete(u.addresses[3]) assert [Address(email_address='a'), Address(email_address='b'), Address(email_address='d')] == list(u.addresses) - sess.clear() + sess.expunge_all() u = sess.query(User).get(u.id) sess.delete(u) @@ -265,7 +265,7 @@ class FlushTest(_fixtures.FixtureTest): sess.delete(u.addresses[3]) assert [Address(email_address='a'), Address(email_address='b'), Address(email_address='d')] == list(u.addresses) - sess.clear() + sess.expunge_all() u = sess.query(User).get(u.id) sess.delete(u) @@ -397,7 +397,7 @@ class DontDereferenceTest(_base.MappedTest): address.user = user session.add(user) session.flush() - session.clear() + session.expunge_all() def query1(): session = create_session(testing.db) diff --git a/test/orm/eager_relations.py b/test/orm/eager_relations.py index 6f4004d8d..2752aae3e 100644 --- a/test/orm/eager_relations.py +++ b/test/orm/eager_relations.py @@ -32,7 +32,7 @@ class EagerTest(_fixtures.FixtureTest): sess.query(User).all() m.add_property("addresses", relation(mapper(Address, addresses))) - sess.clear() + sess.expunge_all() def go(): eq_( [User(id=7, addresses=[Address(id=1, email_address='jack@bean.com')])], @@ -163,7 +163,7 @@ class EagerTest(_fixtures.FixtureTest): sess.query(Address).filter(Address.id.in_([1, 4, 5])), sess.query(Address).filter(Address.id.in_([1, 4, 5])).limit(3) ]: - sess.clear() + sess.expunge_all() eq_(q.all(), [Address(id=1, user=User(id=7)), Address(id=4, user=User(id=8)), @@ -193,12 +193,12 @@ class EagerTest(_fixtures.FixtureTest): sess.query(User).filter(User.id==7), sess.query(User).filter(User.id==7).limit(1) ]: - sess.clear() + sess.expunge_all() eq_(q.all(), [User(id=7, addresses=[Address(id=1)])] ) - sess.clear() + sess.expunge_all() u = sess.query(User).get(7) def go(): assert u.addresses[0].user_id==7 @@ -215,7 +215,7 @@ class EagerTest(_fixtures.FixtureTest): 'dingalings':relation(Dingaling, lazy=False)}) mapper(Dingaling, dingalings, properties={ 'address_id':deferred(dingalings.c.address_id)}) - sess.clear() + sess.expunge_all() def go(): u = sess.query(User).get(8) eq_(User(id=8, @@ -618,7 +618,7 @@ class EagerTest(_fixtures.FixtureTest): self.assertEquals(o1.address, None) self.assert_sql_count(testing.db, go, 2) - sess.clear() + sess.expunge_all() def go(): o1 = sess.query(Order).filter(Order.id==5).one() self.assertEquals(o1.address, None) @@ -810,7 +810,7 @@ class AddEntityTest(_fixtures.FixtureTest): eq_(ret, self._assert_result()) self.assert_sql_count(testing.db, go, 6) - sess.clear() + sess.expunge_all() def go(): ret = sess.query(User, oalias).options(eagerload('addresses'), eagerload(oalias.items)).join(('orders', oalias)).order_by(User.id, oalias.id).all() eq_(ret, self._assert_result()) @@ -890,9 +890,9 @@ class SelfReferentialEagerTest(_base.MappedTest): n1.children[1].append(Node(data='n121')) n1.children[1].append(Node(data='n122')) n1.children[1].append(Node(data='n123')) - sess.save(n1) + sess.add(n1) sess.flush() - sess.clear() + sess.expunge_all() def go(): d = sess.query(Node).filter_by(data='n1').first() assert Node(data='n1', children=[ @@ -924,9 +924,9 @@ class SelfReferentialEagerTest(_base.MappedTest): n1.children[1].append(Node(data='n121')) n1.children[1].append(Node(data='n122')) n1.children[1].append(Node(data='n123')) - sess.save(n1) + sess.add(n1) sess.flush() - sess.clear() + sess.expunge_all() # eager load with join depth 1. when eager load of 'n1' hits the # children of 'n12', no columns are present, eager loader degrades to @@ -961,9 +961,9 @@ class SelfReferentialEagerTest(_base.MappedTest): n1 = Node(data='n1') n1.append(Node(data='n11')) n1.append(Node(data='n12')) - sess.save(n1) + sess.add(n1) sess.flush() - sess.clear() + sess.expunge_all() def go(): self.assertEquals( @@ -972,13 +972,13 @@ class SelfReferentialEagerTest(_base.MappedTest): ) self.assert_sql_count(testing.db, go, 4) - sess.clear() + sess.expunge_all() def go(): assert Node(data='n1', children=[Node(data='n11'), Node(data='n12')]) == sess.query(Node).options(undefer('data')).order_by(Node.id).first() self.assert_sql_count(testing.db, go, 3) - sess.clear() + sess.expunge_all() def go(): assert Node(data='n1', children=[Node(data='n11'), Node(data='n12')]) == sess.query(Node).options(undefer('data'), undefer('children.data')).first() @@ -1002,9 +1002,9 @@ class SelfReferentialEagerTest(_base.MappedTest): n1.children[1].append(Node(data='n121')) n1.children[1].append(Node(data='n122')) n1.children[1].append(Node(data='n123')) - sess.save(n1) + sess.add(n1) sess.flush() - sess.clear() + sess.expunge_all() def go(): d = sess.query(Node).filter_by(data='n1').options(eagerload('children.children')).first() assert Node(data='n1', children=[ @@ -1048,9 +1048,9 @@ class SelfReferentialEagerTest(_base.MappedTest): n1.children[1].append(Node(data='n121')) n1.children[1].append(Node(data='n122')) n1.children[1].append(Node(data='n123')) - sess.save(n1) + sess.add(n1) sess.flush() - sess.clear() + sess.expunge_all() def go(): d = sess.query(Node).filter_by(data='n1').first() assert Node(data='n1', children=[ @@ -1094,9 +1094,9 @@ class SelfReferentialM2MEagerTest(_base.MappedTest): w1 = Widget(name=u'w1') w2 = Widget(name=u'w2') w1.children.append(w2) - sess.save(w1) + sess.add(w1) sess.flush() - sess.clear() + sess.expunge_all() assert [Widget(name='w1', children=[Widget(name='w2')])] == sess.query(Widget).filter(Widget.name==u'w1').all() @@ -1297,10 +1297,10 @@ class SubqueryTest(_base.MappedTest): }) session = create_session() - session.save(User(name='joe', tags=[Tag(score1=5.0, score2=3.0), Tag(score1=55.0, score2=1.0)])) - session.save(User(name='bar', tags=[Tag(score1=5.0, score2=4.0), Tag(score1=50.0, score2=1.0), Tag(score1=15.0, score2=2.0)])) + session.add(User(name='joe', tags=[Tag(score1=5.0, score2=3.0), Tag(score1=55.0, score2=1.0)])) + session.add(User(name='bar', tags=[Tag(score1=5.0, score2=4.0), Tag(score1=50.0, score2=1.0), Tag(score1=15.0, score2=2.0)])) session.flush() - session.clear() + session.expunge_all() for user in session.query(User).all(): eq_(user.query_score, user.prop_score) diff --git a/test/orm/expire.py b/test/orm/expire.py index 7db714506..b18e1ef25 100644 --- a/test/orm/expire.py +++ b/test/orm/expire.py @@ -54,7 +54,7 @@ class ExpireTest(_fixtures.FixtureTest): mapper(User, users) s = create_session() u = s.query(User).get(7) - s.clear() + s.expunge_all() self.assertRaisesMessage(sa.exc.InvalidRequestError, r"is not persistent within this Session", s.expire, u) @@ -162,7 +162,7 @@ class ExpireTest(_fixtures.FixtureTest): u.name = 'somenewname' self.assert_sql_count(testing.db, go, 0) sess.flush() - sess.clear() + sess.expunge_all() assert sess.query(User).get(7).name == 'somenewname' @testing.resolve_artifact_names @@ -585,7 +585,7 @@ class ExpireTest(_fixtures.FixtureTest): sa.orm.clear_mappers() mapper(Order, orders) - sess.clear() + sess.expunge_all() # same tests, using deferred at the options level o = sess.query(Order).options(sa.orm.defer('description')).get(3) @@ -780,7 +780,7 @@ class RefreshTest(_fixtures.FixtureTest): mapper(User, users) s = create_session() u = s.query(User).get(7) - s.clear() + s.expunge_all() self.assertRaisesMessage(sa.exc.InvalidRequestError, r"is not persistent within this Session", lambda: s.refresh(u)) @testing.resolve_artifact_names @@ -844,7 +844,7 @@ class RefreshTest(_fixtures.FixtureTest): s.add(u) s.flush() - s.clear() + s.expunge_all() u = s.query(User).filter(User.name=='Justin').one() s.expire(u) diff --git a/test/orm/inheritance/abc_inheritance.py b/test/orm/inheritance/abc_inheritance.py index 7b14ca929..6415e9919 100644 --- a/test/orm/inheritance/abc_inheritance.py +++ b/test/orm/inheritance/abc_inheritance.py @@ -114,21 +114,21 @@ def produce_test(parent, child, direction): #print "APPENDING", parent.__class__.__name__ , "TO", child.__class__.__name__ - sess.save(parent_obj) + sess.add(parent_obj) parent_obj.collection.append(child_obj) if direction == ONETOMANY: child2 = child_class('child2') parent_obj.collection.append(child2) - sess.save(child2) + sess.add(child2) elif direction == MANYTOONE: parent2 = parent_class('parent2') parent2.collection.append(child_obj) - sess.save(parent2) - sess.save(somea) - sess.save(someb) - sess.save(somec) + sess.add(parent2) + sess.add(somea) + sess.add(someb) + sess.add(somec) sess.flush() - sess.clear() + sess.expunge_all() # assert result via direct get() of parent object result = sess.query(parent_class).get(parent_obj.id) @@ -141,7 +141,7 @@ def produce_test(parent, child, direction): assert result2.id == parent2.id assert result2.collection[0].id == child_obj.id - sess.clear() + sess.expunge_all() # assert result via polymorphic load of parent object result = sess.query(A).filter_by(id=parent_obj.id).one() diff --git a/test/orm/inheritance/abc_polymorphic.py b/test/orm/inheritance/abc_polymorphic.py index 05df5d51e..79e3f880d 100644 --- a/test/orm/inheritance/abc_polymorphic.py +++ b/test/orm/inheritance/abc_polymorphic.py @@ -46,9 +46,9 @@ class ABCTest(ORMTest): sess = create_session() for x in (a1, b1, b2, b3, c1, c2, c3): - sess.save(x) + sess.add(x) sess.flush() - sess.clear() + sess.expunge_all() #for obj in sess.query(A).all(): # print obj diff --git a/test/orm/inheritance/basic.py b/test/orm/inheritance/basic.py index dd0701da4..0068c5534 100644 --- a/test/orm/inheritance/basic.py +++ b/test/orm/inheritance/basic.py @@ -50,14 +50,14 @@ class O2MTest(ORMTest): b1 = Blub("blub #1") b2 = Blub("blub #2") f = Foo("foo #1") - sess.save(b1) - sess.save(b2) - sess.save(f) + sess.add(b1) + sess.add(b2) + sess.add(f) b1.parent_foo = f b2.parent_foo = f sess.flush() compare = ','.join([repr(b1), repr(b2), repr(b1.parent_foo), repr(b2.parent_foo)]) - sess.clear() + sess.expunge_all() l = sess.query(Blub).all() result = ','.join([repr(l[0]), repr(l[1]), repr(l[0].parent_foo), repr(l[1].parent_foo)]) print compare @@ -77,10 +77,10 @@ class FalseDiscriminatorTest(ORMTest): mapper(Bar, inherits=Foo, polymorphic_identity=0) sess = create_session() f1 = Bar() - sess.save(f1) + sess.add(f1) sess.flush() assert f1.type == 0 - sess.clear() + sess.expunge_all() assert isinstance(sess.query(Foo).one(), Bar) class PolymorphicSynonymTest(ORMTest): @@ -111,10 +111,10 @@ class PolymorphicSynonymTest(ORMTest): sess = create_session() at1 = T1(info='at1') at2 = T2(info='at2', data='t2 data') - sess.save(at1) - sess.save(at2) + sess.add(at1) + sess.add(at2) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(T2).filter(T2.info=='at2').one(), at2) self.assertEquals(at2.info, "THE INFO IS:at2") @@ -177,7 +177,7 @@ class CascadeTest(ORMTest): t4_1 = T4(data='t4') t3_1.t4s.append(t4_1) - sess.save(t1_1) + sess.add(t1_1) assert t4_1 in sess.new @@ -230,9 +230,9 @@ class GetTest(ORMTest): f = Foo() b = Bar() bl = Blub() - sess.save(f) - sess.save(b) - sess.save(bl) + sess.add(f) + sess.add(b) + sess.add(bl) sess.flush() if polymorphic: @@ -357,7 +357,7 @@ class FlushTest(ORMTest): admin_mapper = mapper(Admin, admins, inherits=user_mapper) sess = create_session() adminrole = Role() - sess.save(adminrole) + sess.add(adminrole) sess.flush() # create an Admin, and append a Role. the dependency processors @@ -367,7 +367,7 @@ class FlushTest(ORMTest): a = Admin() a.roles.append(adminrole) a.password = 'admin' - sess.save(a) + sess.add(a) sess.flush() assert user_roles.count().scalar() == 1 @@ -396,13 +396,13 @@ class FlushTest(ORMTest): adminrole = Role('admin') sess = create_session() - sess.save(adminrole) + sess.add(adminrole) sess.flush() # create admin user a = Admin(email='tim', password='admin') a.roles.append(adminrole) - sess.save(a) + sess.add(a) sess.flush() a.password = 'sadmin' @@ -446,8 +446,8 @@ class VersioningTest(ORMTest): b1 = Base(value='b1') s1 = Sub(value='sub1', subdata='some subdata') - sess.save(b1) - sess.save(s1) + sess.add(b1) + sess.add(s1) sess.flush() @@ -491,9 +491,9 @@ class VersioningTest(ORMTest): b1 = Base(value='b1') s1 = Sub(value='sub1', subdata='some subdata') s2 = Sub(value='sub2', subdata='some other subdata') - sess.save(b1) - sess.save(s1) - sess.save(s2) + sess.add(b1) + sess.add(s1) + sess.add(s2) sess.flush() @@ -637,16 +637,16 @@ class SyncCompileTest(ORMTest): session = create_session() a = A(data1='a1') - session.save(a) + session.add(a) b = B(data1='b1', data2='b2') - session.save(b) + session.add(b) c = C(data1='c1', data2='c2', data3='c3') - session.save(c) + session.add(c) session.flush() - session.clear() + session.expunge_all() assert len(session.query(A).all()) == 3 assert len(session.query(B).all()) == 2 @@ -852,7 +852,7 @@ class OverrideColKeyTest(ORMTest): sess.add_all([s1, b1]) sess.flush() - sess.clear() + sess.expunge_all() assert sess.query(Base).get(b1.base_id).subdata == "this is base" assert sess.query(Sub).get(s1.base_id).subdata == "this is sub" @@ -877,7 +877,7 @@ class OverrideColKeyTest(ORMTest): sess.add_all([s1, b1]) sess.flush() - sess.clear() + sess.expunge_all() assert sess.query(Base).get(b1.base_id).data == "this is base" assert sess.query(Sub).get(s1.base_id).data == "this is base" @@ -914,9 +914,9 @@ class OptimizedLoadTest(ORMTest): s1 = Sub() s1.data = 's1data' s1.sub = 's1sub' - sess.save(s1) + sess.add(s1) sess.flush() - sess.clear() + sess.expunge_all() # load s1 via Base. s1.id won't populate since it's relative to # the "sub" table. The optimized load kicks in and tries to diff --git a/test/orm/inheritance/concrete.py b/test/orm/inheritance/concrete.py index 225a66da8..6cdaed7e6 100644 --- a/test/orm/inheritance/concrete.py +++ b/test/orm/inheritance/concrete.py @@ -92,10 +92,10 @@ class ConcreteTest(_base.MappedTest): concrete=True, polymorphic_identity='engineer') session = create_session() - session.save(Manager('Tom', 'knows how to manage things')) - session.save(Engineer('Kurt', 'knows how to hack')) + session.add(Manager('Tom', 'knows how to manage things')) + session.add(Engineer('Kurt', 'knows how to hack')) session.flush() - session.clear() + session.expunge_all() assert set([repr(x) for x in session.query(Employee)]) == set(["Engineer Kurt knows how to hack", "Manager Tom knows how to manage things"]) assert set([repr(x) for x in session.query(Manager)]) == set(["Manager Tom knows how to manage things"]) @@ -148,7 +148,7 @@ class ConcreteTest(_base.MappedTest): self.assertEquals(hacker.nickname, "Badass") self.assert_sql_count(testing.db, go, 0) - session.clear() + session.expunge_all() assert repr(session.query(Employee).filter(Employee.name=='Tom').one()) == "Manager Tom knows how to manage things" assert repr(session.query(Manager).filter(Manager.name=='Tom').one()) == "Manager Tom knows how to manage things" @@ -198,7 +198,7 @@ class ConcreteTest(_base.MappedTest): self.assertEquals(hacker.nickname, "Badass") self.assert_sql_count(testing.db, go, 0) - session.clear() + session.expunge_all() # check that we aren't getting a cartesian product in the raw SQL. # this requires that Engineer's polymorphic discriminator is not rendered @@ -300,15 +300,15 @@ class ConcreteTest(_base.MappedTest): c = Company() c.employees.append(Manager('Tom', 'knows how to manage things')) c.employees.append(Engineer('Kurt', 'knows how to hack')) - session.save(c) + session.add(c) session.flush() - session.clear() + session.expunge_all() def go(): c2 = session.query(Company).get(c.id) assert set([repr(x) for x in c2.employees]) == set(["Engineer Kurt knows how to hack", "Manager Tom knows how to manage things"]) self.assert_sql_count(testing.db, go, 2) - session.clear() + session.expunge_all() def go(): c2 = session.query(Company).options(eagerload(Company.employees)).get(c.id) assert set([repr(x) for x in c2.employees]) == set(["Engineer Kurt knows how to hack", "Manager Tom knows how to manage things"]) diff --git a/test/orm/inheritance/magazine.py b/test/orm/inheritance/magazine.py index a0444269d..2557e4116 100644 --- a/test/orm/inheritance/magazine.py +++ b/test/orm/inheritance/magazine.py @@ -24,7 +24,7 @@ class Location(BaseObject): def _set_name(self, name): session = create_session() s = session.query(LocationName).filter(LocationName.name==name).first() - session.clear() + session.expunge_all() if s is not None: self._name = s @@ -193,14 +193,14 @@ def generate_round_trip_test(use_unions=False, use_joins=False): page = ClassifiedPage(magazine=magazine,page_no=1) page2 = MagazinePage(magazine=magazine,page_no=2) page3 = ClassifiedPage(magazine=magazine,page_no=3) - session.save(pub) + session.add(pub) session.flush() print [x for x in session] - session.clear() + session.expunge_all() session.flush() - session.clear() + session.expunge_all() p = session.query(Publication).filter(Publication.name=="Test").one() print p.issues[0].locations[0].magazine.pages diff --git a/test/orm/inheritance/manytomany.py b/test/orm/inheritance/manytomany.py index 43d36e9aa..081bdb823 100644 --- a/test/orm/inheritance/manytomany.py +++ b/test/orm/inheritance/manytomany.py @@ -59,7 +59,7 @@ class InheritTest(ORMTest): g = Group(name="group1") g.users.append(User(name="user1", password="pw", email="foo@bar.com", login_id="lg1")) sess = create_session() - sess.save(g) + sess.add(g) sess.flush() # TODO: put an assertion @@ -94,9 +94,9 @@ class InheritTest2(ORMTest): print class_mapper(Bar).primary_key b = Bar('somedata') sess = create_session() - sess.save(b) + sess.add(b) sess.flush() - sess.clear() + sess.expunge_all() # test that "bar.bid" does not need to be referenced in a get # (ticket 185) @@ -117,7 +117,7 @@ class InheritTest2(ORMTest): sess = create_session() b = Bar('barfoo') - sess.save(b) + sess.add(b) sess.flush() f1 = Foo('subfoo1') @@ -126,7 +126,7 @@ class InheritTest2(ORMTest): b.foos.append(f2) sess.flush() - sess.clear() + sess.expunge_all() l = sess.query(Bar).all() print l[0] @@ -185,12 +185,12 @@ class InheritTest3(ORMTest): sess = create_session() b = Bar('bar #1') - sess.save(b) + sess.add(b) b.foos.append(Foo("foo #1")) b.foos.append(Foo("foo #2")) sess.flush() compare = repr(b) + repr(sorted([repr(o) for o in b.foos])) - sess.clear() + sess.expunge_all() l = sess.query(Bar).all() print repr(l[0]) + repr(l[0].foos) found = repr(l[0]) + repr(sorted([repr(o) for o in l[0].foos])) @@ -225,18 +225,18 @@ class InheritTest3(ORMTest): b2 = Bar("bar #2") bl1 = Blub("blub #1") for o in (f1, b1, b2, bl1): - sess.save(o) + sess.add(o) bl1.foos.append(f1) bl1.bars.append(b2) sess.flush() compare = repr(bl1) blubid = bl1.id - sess.clear() + sess.expunge_all() l = sess.query(Blub).all() print l self.assert_(repr(l[0]) == compare) - sess.clear() + sess.expunge_all() x = sess.query(Blub).filter_by(id=blubid).one() print x self.assert_(repr(x) == compare) diff --git a/test/orm/inheritance/poly_linked_list.py b/test/orm/inheritance/poly_linked_list.py index 5e9f016c1..3fe9f9c8d 100644 --- a/test/orm/inheritance/poly_linked_list.py +++ b/test/orm/inheritance/poly_linked_list.py @@ -150,7 +150,7 @@ class PolymorphicCircularTest(ORMTest): obj = newobj # save to DB - sess.save(t) + sess.add(t) sess.flush() # string version of the saved list @@ -166,7 +166,7 @@ class PolymorphicCircularTest(ORMTest): # clear and query forwards - sess.clear() + sess.expunge_all() node = sess.query(Table1).filter(Table1.id==t.id).first() assertlist = [] while (node): @@ -178,7 +178,7 @@ class PolymorphicCircularTest(ORMTest): forwards = repr(assertlist) # clear and query backwards - sess.clear() + sess.expunge_all() node = sess.query(Table1).filter(Table1.id==obj.id).first() assertlist = [] while (node): diff --git a/test/orm/inheritance/polymorph.py b/test/orm/inheritance/polymorph.py index aa241cea8..aee21fa8d 100644 --- a/test/orm/inheritance/polymorph.py +++ b/test/orm/inheritance/polymorph.py @@ -80,9 +80,9 @@ class InsertOrderTest(PolymorphTest): c.employees.append(Person(status='HHH', name='joesmith')) c.employees.append(Engineer(status='CGG', engineer_name='engineer2', primary_language='python', name='wally')) c.employees.append(Manager(status='ABA', manager_name='manager2', name='jsmith')) - session.save(c) + session.add(c) session.flush() - session.clear() + session.expunge_all() self.assertEquals(session.query(Company).get(c.company_id), c) class RelationToSubclassTest(PolymorphTest): @@ -111,9 +111,9 @@ class RelationToSubclassTest(PolymorphTest): c = Company(name='company1') c.managers.append(Manager(status='AAB', manager_name='manager1', name='pointy haired boss')) - sess.save(c) + sess.add(c) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Company).filter_by(company_id=c.company_id).one(), c) assert c.managers[0].company is c @@ -200,16 +200,16 @@ def generate_round_trip_test(include_base, lazy_relation, redefine_colprop, with session = create_session() c = Company(name='company1') c.employees = employees - session.save(c) + session.add(c) session.flush() - session.clear() + session.expunge_all() self.assertEquals(session.query(Person).get(dilbert.person_id), dilbert) - session.clear() + session.expunge_all() self.assertEquals(session.query(Person).filter(Person.person_id==dilbert.person_id).one(), dilbert) - session.clear() + session.expunge_all() def go(): cc = session.query(Company).get(c.company_id) @@ -253,12 +253,12 @@ def generate_round_trip_test(include_base, lazy_relation, redefine_colprop, with dilbert.engineer_name = 'hes dibert!' session.flush() - session.clear() + session.expunge_all() def go(): session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first() self.assert_sql_count(testing.db, go, 1) - session.clear() + session.expunge_all() dilbert = session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first() def go(): # assert that only primary table is queried for already-present-in-session @@ -267,13 +267,13 @@ def generate_round_trip_test(include_base, lazy_relation, redefine_colprop, with # test standalone orphans daboss = Boss(status='BBB', manager_name='boss', golf_swing='fore', **{person_attribute_name:'daboss'}) - session.save(daboss) + session.add(daboss) self.assertRaises(orm_exc.FlushError, session.flush) c = session.query(Company).first() daboss.company = c manager_list = [e for e in c.employees if isinstance(e, Manager)] session.flush() - session.clear() + session.expunge_all() self.assertEquals(session.query(Manager).order_by(Manager.person_id).all(), manager_list) c = session.query(Company).first() diff --git a/test/orm/inheritance/polymorph2.py b/test/orm/inheritance/polymorph2.py index 78081d506..c5b9b3fde 100644 --- a/test/orm/inheritance/polymorph2.py +++ b/test/orm/inheritance/polymorph2.py @@ -59,9 +59,9 @@ class RelationTest1(ORMTest): p = Person(name='some person') m = Manager(name='some manager') p.manager = m - session.save(p) + session.add(p) session.flush() - session.clear() + session.expunge_all() p = session.query(Person).get(p.person_id) m = session.query(Manager).get(m.person_id) @@ -86,9 +86,9 @@ class RelationTest1(ORMTest): p = Person(name='some person') m = Manager(name='some manager') m.employee = p - session.save(m) + session.add(m) session.flush() - session.clear() + session.expunge_all() p = session.query(Person).get(p.person_id) m = session.query(Manager).get(m.person_id) @@ -178,10 +178,10 @@ class RelationTest2(ORMTest): m.colleague = p if usedata: m.data = Data('ms data') - sess.save(m) + sess.add(m) sess.flush() - sess.clear() + sess.expunge_all() p = sess.query(Person).get(p.person_id) m = sess.query(Manager).get(m.person_id) print p @@ -268,11 +268,11 @@ def generate_test(jointype="join1", usedata=False): p.data = Data('ps data') m.data = Data('ms data') - sess.save(m) - sess.save(p) + sess.add(m) + sess.add(p) sess.flush() - sess.clear() + sess.expunge_all() p = sess.query(Person).get(p.person_id) p2 = sess.query(Person).get(p2.person_id) p3 = sess.query(Person).get(p3.person_id) @@ -357,10 +357,10 @@ class RelationTest4(ORMTest): # creating 5 managers named from M1 to E5 for i in range(1,5): - session.save(Manager(name="M%d" % i,longer_status="YYYYYYYYY")) + session.add(Manager(name="M%d" % i,longer_status="YYYYYYYYY")) # creating 5 engineers named from E1 to E5 for i in range(1,5): - session.save(Engineer(name="E%d" % i,status="X")) + session.add(Engineer(name="E%d" % i,status="X")) session.flush() @@ -368,12 +368,12 @@ class RelationTest4(ORMTest): manager3 = session.query(Manager).filter(Manager.name=="M3").first() car1 = Car(employee=engineer4) - session.save(car1) + session.add(car1) car2 = Car(employee=manager3) - session.save(car2) + session.add(car2) session.flush() - session.clear() + session.expunge_all() def go(): testcar = session.query(Car).options(eagerload('employee')).get(car1.car_id) @@ -394,7 +394,7 @@ class RelationTest4(ORMTest): assert str(usingGet) == "Engineer E4, status X" assert str(usingProperty) == "Engineer E4, status X" - session.clear() + session.expunge_all() print "-----------------------------------------------------------------" # and now for the lightning round, eager ! @@ -403,7 +403,7 @@ class RelationTest4(ORMTest): assert str(testcar.employee) == "Engineer E4, status X" self.assert_sql_count(testing.db, go, 1) - session.clear() + session.expunge_all() s = session.query(Car) c = s.join("employee").filter(Person.name=="E4")[0] assert c.car_id==car1.car_id @@ -459,10 +459,10 @@ class RelationTest5(ORMTest): car1 = Car() car2 = Car() car2.manager = Manager() - sess.save(car1) - sess.save(car2) + sess.add(car1) + sess.add(car2) sess.flush() - sess.clear() + sess.expunge_all() carlist = sess.query(Car).all() assert carlist[0].manager is None @@ -503,10 +503,10 @@ class RelationTest6(ORMTest): m = Manager(name='manager1') m2 =Manager(name='manager2') m.colleague = m2 - sess.save(m) + sess.add(m) sess.flush() - sess.clear() + sess.expunge_all() m = sess.query(Manager).get(m.person_id) m2 = sess.query(Manager).get(m2.person_id) assert m.colleague is m2 @@ -601,10 +601,10 @@ class RelationTest7(ORMTest): car=Car() else: car=Offraod_Car() - session.save(Manager(name="M%d" % i,category="YYYYYYYYY",car=car)) - session.save(Engineer(name="E%d" % i,field="X",car=car)) + session.add(Manager(name="M%d" % i,category="YYYYYYYYY",car=car)) + session.add(Engineer(name="E%d" % i,field="X",car=car)) session.flush() - session.clear() + session.expunge_all() r = session.query(Person).all() for p in r: @@ -697,8 +697,8 @@ class GenerativeTest(TestBase, AssertsExecutionResults): active = Status(name="active") dead = Status(name="dead") - session.save(active) - session.save(dead) + session.add(active) + session.add(dead) session.flush() # TODO: we haven't created assertions for all the data combinations created here @@ -710,8 +710,8 @@ class GenerativeTest(TestBase, AssertsExecutionResults): st=active else: st=dead - session.save(Manager(name="M%d" % i,category="YYYYYYYYY",status=st)) - session.save(Engineer(name="E%d" % i,field="X",status=st)) + session.add(Manager(name="M%d" % i,category="YYYYYYYYY",status=st)) + session.add(Engineer(name="E%d" % i,field="X",status=st)) session.flush() @@ -721,8 +721,8 @@ class GenerativeTest(TestBase, AssertsExecutionResults): # create 2 cars for E4, one active and one dead car1 = Car(employee=engineer4,status=active) car2 = Car(employee=engineer4,status=dead) - session.save(car1) - session.save(car2) + session.add(car1) + session.add(car2) session.flush() # this particular adapt used to cause a recursion overflow; @@ -807,9 +807,9 @@ class MultiLevelTest(ORMTest): c = Manager().set( name= 'head', machine= 'fast', duties= 'many') session = create_session() - session.save(a) - session.save(b) - session.save(c) + session.add(a) + session.add(b) + session.add(c) session.flush() assert set(session.query(Employee).all()) == set([a,b,c]) assert set(session.query( Engineer).all()) == set([b,c]) @@ -898,10 +898,10 @@ class CustomPKTest(ORMTest): ot1 = T1() ot2 = T2() sess = create_session() - sess.save(ot1) - sess.save(ot2) + sess.add(ot1) + sess.add(ot2) sess.flush() - sess.clear() + sess.expunge_all() # query using get(), using only one value. this requires the select_table mapper # has the same single-col primary key. @@ -935,10 +935,10 @@ class CustomPKTest(ORMTest): ot1 = T1() ot2 = T2() sess = create_session() - sess.save(ot1) - sess.save(ot2) + sess.add(ot1) + sess.add(ot2) sess.flush() - sess.clear() + sess.expunge_all() # query using get(), using only one value. this requires the select_table mapper # has the same single-col primary key. @@ -995,7 +995,7 @@ class InheritingEagerTest(ORMTest): session = create_session() bob = Employee() - session.save(bob) + session.add(bob) tag = Tag('crazy') bob.tags.append(tag) @@ -1004,7 +1004,7 @@ class InheritingEagerTest(ORMTest): bob.tags.append(tag) session.flush() - session.clear() + session.expunge_all() # query from Employee with limit, query needs to apply eager limiting subquery instance = session.query(Employee).filter_by(id=1).limit(1).first() assert len(instance.tags) == 2 @@ -1052,10 +1052,10 @@ class MissingPolymorphicOnTest(ORMTest): c = C(cdata='c1', adata='a1', b=B(data='c')) d = D(cdata='c2', adata='a2', ddata='d2', b=B(data='d')) sess = create_session() - sess.save(c) - sess.save(d) + sess.add(c) + sess.add(d) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(A).all(), [C(cdata='c1', adata='a1'), D(cdata='c2', adata='a2', ddata='d2')]) if __name__ == "__main__": diff --git a/test/orm/inheritance/productspec.py b/test/orm/inheritance/productspec.py index ba4828c69..63c6a24fe 100644 --- a/test/orm/inheritance/productspec.py +++ b/test/orm/inheritance/productspec.py @@ -113,10 +113,10 @@ class InheritTest(ORMTest): d1 = Detail(name='d1') a1.specification.append(SpecLine(slave=d1)) - session.save(a1) + session.add(a1) orig = repr(a1) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) @@ -145,11 +145,11 @@ class InheritTest(ORMTest): s = SpecLine(slave=Product(name='p1')) s2 = SpecLine(slave=Detail(name='d1')) - session.save(s) - session.save(s2) + session.add(s) + session.add(s2) orig = repr([s, s2]) session.flush() - session.clear() + session.expunge_all() new = repr(session.query(SpecLine).all()) print orig print new @@ -197,10 +197,10 @@ class InheritTest(ORMTest): a1.specification.append(SpecLine(slave=Detail(name='d1'))) a1.documents.append(Document('doc1')) a1.documents.append(RasterDocument('doc2')) - session.save(a1) + session.add(a1) orig = repr(a1) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) @@ -235,10 +235,10 @@ class InheritTest(ORMTest): a1 = Assembly(name='a1') a1.documents.append(RasterDocument('doc2')) - session.save(a1) + session.add(a1) orig = repr(a1) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) @@ -248,7 +248,7 @@ class InheritTest(ORMTest): del a1.documents[0] session.flush() - session.clear() + session.expunge_all() a1 = session.query(Product).filter_by(name='a1').one() assert len(session.query(Document).all()) == 0 @@ -302,10 +302,10 @@ class InheritTest(ORMTest): a1.specification.append(SpecLine(slave=Detail(name='d1'))) a1.documents.append(Document('doc1')) a1.documents.append(RasterDocument('doc2')) - session.save(a1) + session.add(a1) orig = repr(a1) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Product).filter_by(name='a1').one() new = repr(a1) diff --git a/test/orm/inheritance/query.py b/test/orm/inheritance/query.py index f362ea097..fe948931b 100644 --- a/test/orm/inheritance/query.py +++ b/test/orm/inheritance/query.py @@ -166,10 +166,10 @@ def make_test(select_type): c2.employees = [e3] sess = create_session() - sess.save(c1) - sess.save(c2) + sess.add(c1) + sess.add(c2) sess.flush() - sess.clear() + sess.expunge_all() all_employees = [e1, e2, b1, m1, e3] c1_employees = [e1, e2, b1, m1] @@ -239,13 +239,13 @@ def make_test(select_type): sess = create_session() for aliased in (True, False): - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Person).with_polymorphic(Manager).join('paperwork', aliased=aliased).filter(Paperwork.description.like('%review%')).all(), [b1, m1]) - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Person).with_polymorphic([Manager, Engineer]).join('paperwork', aliased=aliased).filter(Paperwork.description.like('%#2%')).all(), [e1, m1]) - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Person).with_polymorphic([Manager, Engineer]).join('paperwork', aliased=aliased).filter(Person.name.like('%dog%')).filter(Paperwork.description.like('%#2%')).all(), [m1]) def test_join_to_polymorphic(self): @@ -340,22 +340,22 @@ def make_test(select_type): self.assertEquals(sess.query(Person).with_polymorphic(Engineer).filter(Engineer.primary_language=='java').all(), emps_without_relations[0:1]) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): self.assertEquals(sess.query(Person).with_polymorphic('*').all(), emps_without_relations) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): self.assertEquals(sess.query(Person).with_polymorphic(Engineer).all(), emps_without_relations) self.assert_sql_count(testing.db, go, 3) - sess.clear() + sess.expunge_all() def go(): self.assertEquals(sess.query(Person).with_polymorphic(Engineer, people.outerjoin(engineers)).all(), emps_without_relations) self.assert_sql_count(testing.db, go, 3) - sess.clear() + sess.expunge_all() def go(): # limit the polymorphic join down to just "Person", overriding select_table self.assertEquals(sess.query(Person).with_polymorphic(Person).all(), emps_without_relations) @@ -719,10 +719,10 @@ class SelfReferentialTestJoinedToBase(ORMTest): p1 = Person(name='dogbert') e1 = Engineer(name='dilbert', primary_language='java', reports_to=p1) sess = create_session() - sess.save(p1) - sess.save(e1) + sess.add(p1) + sess.add(e1) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Engineer).filter(Engineer.reports_to.has(Person.name=='dogbert')).first(), Engineer(name='dilbert')) @@ -739,10 +739,10 @@ class SelfReferentialTestJoinedToBase(ORMTest): p1 = Person(name='dogbert') e1 = Engineer(name='dilbert', primary_language='java', reports_to=p1) sess = create_session() - sess.save(p1) - sess.save(e1) + sess.add(p1) + sess.add(e1) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals( sess.query(Engineer).join('reports_to', aliased=True).filter(Person.name=='dogbert').first(), @@ -781,10 +781,10 @@ class SelfReferentialTestJoinedToJoined(ORMTest): m1 = Manager(name='dogbert') e1 = Engineer(name='dilbert', primary_language='java', reports_to=m1) sess = create_session() - sess.save(m1) - sess.save(e1) + sess.add(m1) + sess.add(e1) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Engineer).filter(Engineer.reports_to.has(Manager.name=='dogbert')).first(), Engineer(name='dilbert')) @@ -792,10 +792,10 @@ class SelfReferentialTestJoinedToJoined(ORMTest): m1 = Manager(name='dogbert') e1 = Engineer(name='dilbert', primary_language='java', reports_to=m1) sess = create_session() - sess.save(m1) - sess.save(e1) + sess.add(m1) + sess.add(e1) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals( sess.query(Engineer).join('reports_to', aliased=True).filter(Manager.name=='dogbert').first(), @@ -847,8 +847,8 @@ class M2MFilterTest(ORMTest): org2 = Organization(name='org2', engineers=[e3, e4]) sess = create_session() - sess.save(org1) - sess.save(org2) + sess.add(org1) + sess.add(org2) sess.flush() def test_not_contains(self): diff --git a/test/orm/inheritance/single.py b/test/orm/inheritance/single.py index 19c9a83f2..8134d86c4 100644 --- a/test/orm/inheritance/single.py +++ b/test/orm/inheritance/single.py @@ -227,7 +227,7 @@ class RelationToSingleTest(MappedTest): e2 = JuniorEngineer(name='Ed', engineer_info='oh that ed', company=c1) sess.add_all([c1, c2, m1, m2, e1, e2]) sess.commit() - sess.clear() + sess.expunge_all() self.assertEquals( sess.query(Company).filter(Company.employees.of_type(JuniorEngineer).any()).all(), [ @@ -269,7 +269,7 @@ class RelationToSingleTest(MappedTest): self.assertEquals(c1.engineers, [e2]) self.assertEquals(c2.engineers, [e1]) - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Company).order_by(Company.name).all(), [ Company(name='c1', engineers=[JuniorEngineer(name='Ed')]), @@ -278,7 +278,7 @@ class RelationToSingleTest(MappedTest): ) # eager load join should limit to only "Engineer" - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Company).options(eagerload('engineers')).order_by(Company.name).all(), [ Company(name='c1', engineers=[JuniorEngineer(name='Ed')]), @@ -287,7 +287,7 @@ class RelationToSingleTest(MappedTest): ) # join() to Company.engineers, Employee as the requested entity - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Company, Employee).join(Company.engineers).order_by(Company.name).all(), [ (Company(name='c1'), JuniorEngineer(name='Ed')), @@ -297,7 +297,7 @@ class RelationToSingleTest(MappedTest): # join() to Company.engineers, Engineer as the requested entity. # this actually applies the IN criterion twice which is less than ideal. - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Company, Engineer).join(Company.engineers).order_by(Company.name).all(), [ (Company(name='c1'), JuniorEngineer(name='Ed')), @@ -306,7 +306,7 @@ class RelationToSingleTest(MappedTest): ) # join() to Company.engineers without any Employee/Engineer entity - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Company).join(Company.engineers).filter(Engineer.name.in_(['Tom', 'Kurt'])).all(), [ Company(name='c2') @@ -321,7 +321,7 @@ class RelationToSingleTest(MappedTest): # section to "inheritance" laying out all the various behaviors Query has. @testing.fails_on_everything_except() def go(): - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Company).\ filter(Company.company_id==Engineer.company_id).filter(Engineer.name.in_(['Tom', 'Kurt'])).all(), [ @@ -359,29 +359,29 @@ class SingleOnJoinedTest(ORMTest): mapper(Manager, inherits=Employee,polymorphic_identity='manager') sess = create_session() - sess.save(Person(name='p1')) - sess.save(Employee(name='e1', employee_data='ed1')) - sess.save(Manager(name='m1', employee_data='ed2', manager_data='md1')) + sess.add(Person(name='p1')) + sess.add(Employee(name='e1', employee_data='ed1')) + sess.add(Manager(name='m1', employee_data='ed2', manager_data='md1')) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Person).order_by(Person.person_id).all(), [ Person(name='p1'), Employee(name='e1', employee_data='ed1'), Manager(name='m1', employee_data='ed2', manager_data='md1') ]) - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Employee).order_by(Person.person_id).all(), [ Employee(name='e1', employee_data='ed1'), Manager(name='m1', employee_data='ed2', manager_data='md1') ]) - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(Manager).order_by(Person.person_id).all(), [ Manager(name='m1', employee_data='ed2', manager_data='md1') ]) - sess.clear() + sess.expunge_all() def go(): self.assertEquals(sess.query(Person).with_polymorphic('*').order_by(Person.person_id).all(), [ diff --git a/test/orm/lazy_relations.py b/test/orm/lazy_relations.py index 05f752bf6..4ac8a13ef 100644 --- a/test/orm/lazy_relations.py +++ b/test/orm/lazy_relations.py @@ -329,7 +329,7 @@ class M2OGetTest(_fixtures.FixtureTest): ad1 = Address(email_address='somenewaddress', id=12) sess.add(ad1) sess.flush() - sess.clear() + sess.expunge_all() ad2 = sess.query(Address).get(1) ad3 = sess.query(Address).get(ad1.id) diff --git a/test/orm/manytomany.py b/test/orm/manytomany.py index 61409c716..23af3bd1f 100644 --- a/test/orm/manytomany.py +++ b/test/orm/manytomany.py @@ -105,7 +105,7 @@ class M2MTest(_base.MappedTest): p3.places.append(p4) sess.flush() - sess.clear() + sess.expunge_all() l = sess.query(Place).order_by(place.c.place_id).all() (p1, p2, p3, p4, p5, p6, p7) = l assert p1.places == [p2,p3,p5] @@ -146,7 +146,7 @@ class M2MTest(_base.MappedTest): sess.add(tran) sess.flush() - sess.clear() + sess.expunge_all() r = sess.query(Transition).all() self.assert_unordered_result(r, Transition, {'name': 'transition1', @@ -227,7 +227,7 @@ class M2MTest2(_base.MappedTest): self.assert_(len(c1.students) == 1) sess.add(s1) sess.flush() - sess.clear() + sess.expunge_all() s = sess.query(Student).filter_by(name='Student1').one() c = sess.query(Course).filter_by(name='Course3').one() self.assert_(len(s.courses) == 3) diff --git a/test/orm/mapper.py b/test/orm/mapper.py index eaceb9230..72e417d26 100644 --- a/test/orm/mapper.py +++ b/test/orm/mapper.py @@ -282,7 +282,7 @@ class MapperTest(_fixtures.FixtureTest): u.name = 'ed' u3 = User() u3.name = 'some user' - sess.save(u3) + sess.add(u3) sess.flush() sess.rollback() @@ -304,7 +304,7 @@ class MapperTest(_fixtures.FixtureTest): m = mapper(User, users) m.add_property('name', synonym('_name', map_column=True)) - sess.clear() + sess.expunge_all() u = sess.query(User).filter_by(name='jack').one() eq_(u._name, 'jack') eq_(u.name, 'jack') @@ -805,7 +805,7 @@ class MapperTest(_fixtures.FixtureTest): eq_(u.uc_name, "SOME USER NAME") sess.flush() - sess.clear() + sess.expunge_all() q = sess.query(User) u2 = q.filter(User.name=='some user name').one() @@ -992,7 +992,7 @@ class OptionsTest(_fixtures.FixtureTest): eq_(len(u.addresses), 3) self.sql_count_(0, go) - sess.clear() + sess.expunge_all() u = sess.query(User).filter_by(id=8).one() eq_(u.id, 8) @@ -1027,7 +1027,7 @@ class OptionsTest(_fixtures.FixtureTest): eq_(l, self.static.user_address_result) self.sql_count_(1, go) - sess.clear() + sess.expunge_all() # then select just from users. run it into instances. # then assert the data, which will launch 3 more lazy loads @@ -1073,7 +1073,7 @@ class OptionsTest(_fixtures.FixtureTest): eq_(l, self.static.user_all_result) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() # then select just from users. run it into instances. # then assert the data, which will launch 6 more lazy loads @@ -1189,7 +1189,7 @@ class ValidatorTest(_fixtures.FixtureTest): eq_(u1.name, 'ed modified') sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).filter_by(name='ed modified').one(), User(name='ed')) @@ -1209,7 +1209,7 @@ class ValidatorTest(_fixtures.FixtureTest): u1.addresses.append(Address(id=15, email_address='foo@bar.com')) sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() eq_( sess.query(User).filter_by(name='edward').one(), User(name='edward', addresses=[Address(email_address='foo@bar.com')]) @@ -1329,7 +1329,7 @@ class DeferredTest(_fixtures.FixtureTest): sess = create_session() o = Order() - sess.save(o) + sess.add(o) o.id = 7 def go(): o.description = "some description" @@ -1368,7 +1368,7 @@ class DeferredTest(_fixtures.FixtureTest): sess = create_session() o = Order() - sess.save(o) + sess.add(o) o.id = 7 def go(): o.description = "some description" @@ -1382,7 +1382,7 @@ class DeferredTest(_fixtures.FixtureTest): sess = create_session() o = Order() - sess.save(o) + sess.add(o) def go(): o.description = "some description" self.sql_count_(0, go) @@ -1497,7 +1497,7 @@ class DeferredTest(_fixtures.FixtureTest): ("SELECT orders.user_id AS orders_user_id " "FROM orders WHERE orders.id = :param_1", {'param_1':1})]) - sess.clear() + sess.expunge_all() q2 = q.options(sa.orm.undefer('user_id')) self.sql_eq_(q2.all, [ @@ -1573,7 +1573,7 @@ class DeferredTest(_fixtures.FixtureTest): self.sql_count_(1, go) eq_(item.description, 'item 4') - sess.clear() + sess.expunge_all() l = q.options(sa.orm.undefer('orders.items.description')).all() item = l[0].orders[1].items[1] def go(): @@ -1623,7 +1623,7 @@ class DeferredPopulationTest(_base.MappedTest): def test_query_twice_with_clear(self): session = create_session() result = session.query(Thing).first() - session.clear() + session.expunge_all() thing = session.query(Thing).options(sa.orm.undefer("name")).first() self._test(thing) @@ -1638,7 +1638,7 @@ class DeferredPopulationTest(_base.MappedTest): def test_eagerload_with_clear(self): session = create_session() human = session.query(Human).options(sa.orm.eagerload("thing")).first() - session.clear() + session.expunge_all() thing = session.query(Thing).options(sa.orm.undefer("name")).first() self._test(thing) @@ -1653,7 +1653,7 @@ class DeferredPopulationTest(_base.MappedTest): def test_join_with_clear(self): session = create_session() result = session.query(Human).add_entity(Thing).join("thing").first() - session.clear() + session.expunge_all() thing = session.query(Thing).options(sa.orm.undefer("name")).first() self._test(thing) @@ -1729,10 +1729,10 @@ class CompositeTypesTest(_base.MappedTest): g.version_id=1 g.edges.append(Edge(Point(3, 4), Point(5, 6))) g.edges.append(Edge(Point(14, 5), Point(2, 7))) - sess.save(g) + sess.add(g) sess.flush() - sess.clear() + sess.expunge_all() g2 = sess.query(Graph).get([g.id, g.version_id]) for e1, e2 in zip(g.edges, g2.edges): eq_(e1.start, e2.start) @@ -1740,19 +1740,19 @@ class CompositeTypesTest(_base.MappedTest): g2.edges[1].end = Point(18, 4) sess.flush() - sess.clear() + sess.expunge_all() e = sess.query(Edge).get(g2.edges[1].id) eq_(e.end, Point(18, 4)) e.end.x = 19 e.end.y = 5 sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(Edge).get(g2.edges[1].id).end, Point(19, 5)) g.edges[1].end = Point(19, 5) - sess.clear() + sess.expunge_all() def go(): g2 = (sess.query(Graph). options(sa.orm.eagerload('edges'))).get([g.id, g.version_id]) @@ -1798,13 +1798,13 @@ class CompositeTypesTest(_base.MappedTest): sess = create_session() g = Graph(Version(1, 1)) - sess.save(g) + sess.add(g) sess.flush() - sess.clear() + sess.expunge_all() g2 = sess.query(Graph).get([1, 1]) eq_(g.version, g2.version) - sess.clear() + sess.expunge_all() g2 = sess.query(Graph).get(Version(1, 1)) eq_(g.version, g2.version) @@ -1825,9 +1825,9 @@ class CompositeTypesTest(_base.MappedTest): @testing.fails_on_everything_except("sqlite") def go(): g = Graph(Version(2, None)) - sess.save(g) + sess.add(g) sess.flush() - sess.clear() + sess.expunge_all() g2 = sess.query(Graph).filter_by(version=Version(2, None)).one() eq_(g.version, g2.version) go() @@ -1858,7 +1858,7 @@ class CompositeTypesTest(_base.MappedTest): sess = create_session() f1 = Foobar() f1.foob = FBComposite(None, 5, None, None) - sess.save(f1) + sess.add(f1) sess.flush() assert f1.foob == FBComposite(2, 5, 15, None) @@ -1894,7 +1894,7 @@ class CompositeTypesTest(_base.MappedTest): sess = create_session() f1 = Foobar() f1.foob = FBComposite(None, 5, None, None) - sess.save(f1) + sess.add(f1) sess.flush() assert f1.foob == FBComposite(2, 5, 15, None) @@ -1941,10 +1941,10 @@ class CompositeTypesTest(_base.MappedTest): e = Edge(None, None) g.edges.append(e) - sess.save(g) + sess.add(g) sess.flush() - sess.clear() + sess.expunge_all() g2 = sess.query(Graph).get([1, 1]) assert g2.edges[-1].start.x is None @@ -2064,10 +2064,10 @@ class MapperExtensionTest(_fixtures.FixtureTest): mapper(User, users, extension=Ext()) sess = create_session() u = User(name='u1') - sess.save(u) + sess.add(u) sess.flush() u = sess.query(User).populate_existing().get(u.id) - sess.clear() + sess.expunge_all() u = sess.query(User).get(u.id) u.name = 'u1 changed' sess.flush() @@ -2092,10 +2092,10 @@ class MapperExtensionTest(_fixtures.FixtureTest): sess = create_session() am = AdminUser(name='au1', email_address='au1@e1') - sess.save(am) + sess.add(am) sess.flush() am = sess.query(AdminUser).populate_existing().get(am.id) - sess.clear() + sess.expunge_all() am = sess.query(AdminUser).get(am.id) am.name = 'au1 changed' sess.flush() @@ -2122,8 +2122,8 @@ class MapperExtensionTest(_fixtures.FixtureTest): sess = create_session() i1 = Item(description="i1") k1 = Keyword(name="k1") - sess.save(i1) - sess.save(k1) + sess.add(i1) + sess.add(k1) sess.flush() eq_(methods, ['instrument_class', 'instrument_class', 'init_instance', @@ -2150,10 +2150,10 @@ class MapperExtensionTest(_fixtures.FixtureTest): sess = create_session() am = AdminUser(name="au1", email_address="au1@e1") - sess.save(am) + sess.add(am) sess.flush() am = sess.query(AdminUser).populate_existing().get(am.id) - sess.clear() + sess.expunge_all() am = sess.query(AdminUser).get(am.id) am.name = 'au1 changed' sess.flush() @@ -2179,7 +2179,7 @@ class MapperExtensionTest(_fixtures.FixtureTest): u1.name = 'ed' sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() assert sess.query(User).first() @@ -2280,7 +2280,7 @@ class RequirementsTest(_base.MappedTest): s = create_session() for i in range(3): h1 = H1() - s.save(h1) + s.add(h1) h1.h2s.append(H2()) h1.h3s.extend([H3(), H3()]) @@ -2360,9 +2360,9 @@ class MagicNamesTest(_base.MappedTest): m = Map(state='AK', mapper=c) sess = create_session() - sess.save(c) + sess.add(c) sess.flush() - sess.clear() + sess.expunge_all() for C, M in ((Cartographer, Map), (sa.orm.aliased(Cartographer), sa.orm.aliased(Map))): diff --git a/test/orm/merge.py b/test/orm/merge.py index ba3be1ca6..ab56dd978 100644 --- a/test/orm/merge.py +++ b/test/orm/merge.py @@ -35,7 +35,7 @@ class MergeTest(_fixtures.FixtureTest): assert u2 in sess eq_(u2, User(id=7, name='fred')) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).first(), User(id=7, name='fred')) @testing.resolve_artifact_names @@ -62,7 +62,7 @@ class MergeTest(_fixtures.FixtureTest): assert merged_users[0] is not u sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).one(), User(id=7, name='fred', addresses=OrderedSet([ @@ -80,7 +80,7 @@ class MergeTest(_fixtures.FixtureTest): u = User(id=7, name='fred') sess.add(u) sess.flush() - sess.clear() + sess.expunge_all() eq_(on_load.called, 0) @@ -90,7 +90,7 @@ class MergeTest(_fixtures.FixtureTest): assert u2 is not _u2 eq_(on_load.called, 1) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).first(), User(id=7, name='fred jones')) eq_(on_load.called, 2) @@ -114,7 +114,7 @@ class MergeTest(_fixtures.FixtureTest): sess = create_session() sess.add(u) sess.flush() - sess.clear() + sess.expunge_all() eq_(on_load.called, 0) @@ -138,7 +138,7 @@ class MergeTest(_fixtures.FixtureTest): ])) ) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).one(), User(id=7, name='fred', addresses=OrderedSet([ Address(id=3, email_address='fred3'), @@ -164,7 +164,7 @@ class MergeTest(_fixtures.FixtureTest): sess = create_session() sess.add(u) sess.flush() - sess.clear() + sess.expunge_all() u.name='fred jones' u.addresses.add(Address(id=3, email_address='fred3')) @@ -174,7 +174,7 @@ class MergeTest(_fixtures.FixtureTest): u = sess.merge(u) eq_(on_load.called, 4) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(User).first(), User(id=7, name='fred jones', addresses=OrderedSet([ @@ -212,7 +212,7 @@ class MergeTest(_fixtures.FixtureTest): Address(email_address='hoho@bar.com')])) sess.flush() - sess.clear() + sess.expunge_all() u2 = sess.query(User).get(7) eq_(u2, User(id=7, name='fred', addresses=[ @@ -267,7 +267,7 @@ class MergeTest(_fixtures.FixtureTest): sess3.flush() # assert modified/merged data was saved - sess.clear() + sess.expunge_all() u = sess.query(User).get(7) eq_(u, User(id=7, name='fred2', addresses=[ Address(email_address='foo@bar.com'), @@ -605,7 +605,7 @@ class MergeTest(_fixtures.FixtureTest): assert not sa.orm.object_mapper(a2)._is_orphan( sa.orm.attributes.instance_state(a2)) sess2.flush() - sess2.clear() + sess2.expunge_all() eq_(sess2.query(User).get(u2.id).addresses[0].email_address, 'somenewaddress') @@ -631,7 +631,7 @@ class MergeTest(_fixtures.FixtureTest): assert not sa.orm.object_mapper(a2)._is_orphan( sa.orm.attributes.instance_state(a2)) sess2.flush() - sess2.clear() + sess2.expunge_all() eq_(sess2.query(User).get(u2.id).addresses[0].email_address, 'somenewaddress') except sa.exc.InvalidRequestError, e: @@ -660,7 +660,7 @@ class MergeTest(_fixtures.FixtureTest): sess = create_session() u = User() u.name = 'ed' - sess.save(u) + sess.add(u) sess.flush() sess.expunge(u) sess.merge(u) diff --git a/test/orm/naturalpks.py b/test/orm/naturalpks.py index 58ebea6ca..980165fc0 100644 --- a/test/orm/naturalpks.py +++ b/test/orm/naturalpks.py @@ -57,7 +57,7 @@ class NaturalPKTest(_base.MappedTest): assert sess.query(User).get('jack') is None - sess.clear() + sess.expunge_all() u1 = sess.query(User).get('ed') self.assertEquals(User(username='ed', fullname='jack'), u1) @@ -80,7 +80,7 @@ class NaturalPKTest(_base.MappedTest): sess.expire(u1) self.assertRaises(sa.orm.exc.ObjectDeletedError, getattr, u1, 'username') - sess.clear() + sess.expunge_all() assert sess.query(User).get('jack') is None assert sess.query(User).get('ed').fullname == 'jack' @@ -97,7 +97,7 @@ class NaturalPKTest(_base.MappedTest): sess.expire(u1) u1.username = 'ed' sess.flush() - sess.clear() + sess.expunge_all() assert sess.query(User).get('ed').fullname == 'jack' @@ -129,7 +129,7 @@ class NaturalPKTest(_base.MappedTest): sess.flush() assert u1.addresses[0].username == 'ed' - sess.clear() + sess.expunge_all() self.assertEquals([Address(username='ed'), Address(username='ed')], sess.query(Address).all()) u1 = sess.query(User).get('ed') @@ -140,14 +140,14 @@ class NaturalPKTest(_base.MappedTest): self.assert_sql_count(testing.db, go, 4) # test passive_updates=False; load addresses, update user, update 2 addresses else: self.assert_sql_count(testing.db, go, 1) # test passive_updates=True; update user - sess.clear() + sess.expunge_all() assert User(username='jack', addresses=[Address(username='jack'), Address(username='jack')]) == sess.query(User).get('jack') u1 = sess.query(User).get('jack') u1.addresses = [] u1.username = 'fred' sess.flush() - sess.clear() + sess.expunge_all() assert sess.query(Address).get('jack1').username is None u1 = sess.query(User).get('fred') self.assertEquals(User(username='fred', fullname='jack'), u1) @@ -195,7 +195,7 @@ class NaturalPKTest(_base.MappedTest): self.assert_sql_count(testing.db, go, 0) assert a1.username == a2.username == 'ed' - sess.clear() + sess.expunge_all() self.assertEquals([Address(username='ed'), Address(username='ed')], sess.query(Address).all()) @testing.fails_on('sqlite', 'FIXME: unknown') @@ -234,7 +234,7 @@ class NaturalPKTest(_base.MappedTest): else: self.assert_sql_count(testing.db, go, 3) self.assertEquals([Address(username='ed'), Address(username='ed')], [ad1, ad2]) - sess.clear() + sess.expunge_all() self.assertEquals([Address(username='ed'), Address(username='ed')], sess.query(Address).all()) u1 = sess.query(User).get('ed') @@ -248,7 +248,7 @@ class NaturalPKTest(_base.MappedTest): self.assert_sql_count(testing.db, go, 1) else: self.assert_sql_count(testing.db, go, 3) - sess.clear() + sess.expunge_all() self.assertEquals([Address(username='fred'), Address(username='fred')], sess.query(Address).all()) @@ -296,14 +296,14 @@ class NaturalPKTest(_base.MappedTest): sess.flush() self.assert_sql_count(testing.db, go, 0) - sess.clear() + sess.expunge_all() r = sess.query(Item).all() self.assertEquals(Item(itemname='item1'), r[0]) self.assertEquals(['jack'], [u.username for u in r[0].users]) self.assertEquals(Item(itemname='item2'), r[1]) self.assertEquals(['ed', 'jack'], sorted([u.username for u in r[1].users])) - sess.clear() + sess.expunge_all() u2 = sess.query(User).get(u2.username) u2.username='wendy' sess.flush() @@ -400,7 +400,7 @@ class NonPKCascadeTest(_base.MappedTest): assert u1.addresses[0].username == 'ed' self.assertEquals(sa.select([addresses.c.username]).execute().fetchall(), [('ed',), ('ed',)]) - sess.clear() + sess.expunge_all() self.assertEquals([Address(username='ed'), Address(username='ed')], sess.query(Address).all()) u1 = sess.query(User).get(u1.id) @@ -411,15 +411,15 @@ class NonPKCascadeTest(_base.MappedTest): self.assert_sql_count(testing.db, go, 4) # test passive_updates=False; load addresses, update user, update 2 addresses else: self.assert_sql_count(testing.db, go, 1) # test passive_updates=True; update user - sess.clear() + sess.expunge_all() assert User(username='jack', addresses=[Address(username='jack'), Address(username='jack')]) == sess.query(User).get(u1.id) - sess.clear() + sess.expunge_all() u1 = sess.query(User).get(u1.id) u1.addresses = [] u1.username = 'fred' sess.flush() - sess.clear() + sess.expunge_all() a1 = sess.query(Address).get(a1.id) self.assertEquals(a1.username, None) diff --git a/test/orm/onetoone.py b/test/orm/onetoone.py index d159d20f4..1ed3dcc61 100644 --- a/test/orm/onetoone.py +++ b/test/orm/onetoone.py @@ -52,7 +52,7 @@ class O2OTest(_base.MappedTest): p.jack = None assert j.port is None - ctx.clear() + ctx.expunge_all() j = ctx.query(Jack).get(jid) p = ctx.query(Port).get(pid) diff --git a/test/orm/pickled.py b/test/orm/pickled.py index d14acdc50..ca308bb5b 100644 --- a/test/orm/pickled.py +++ b/test/orm/pickled.py @@ -26,7 +26,7 @@ class PickleTest(_fixtures.FixtureTest): sess.add(u2) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(u1, sess.query(User).get(u2.id)) @@ -44,14 +44,14 @@ class PickleTest(_fixtures.FixtureTest): u1.addresses.append(Address(email_address='ed@bar.com')) sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() u1 = sess.query(User).get(u1.id) assert 'name' not in u1.__dict__ assert 'addresses' not in u1.__dict__ u2 = pickle.loads(pickle.dumps(u1)) sess2 = create_session() - sess2.update(u2) + sess2.add(u2) self.assertEquals(u2.name, 'ed') self.assertEquals(u2, User(name='ed', addresses=[Address(email_address='ed@bar.com')])) @@ -73,7 +73,7 @@ class PickleTest(_fixtures.FixtureTest): u1.addresses.append(Address(email_address='ed@bar.com')) sess.add(u1) sess.flush() - sess.clear() + sess.expunge_all() u1 = sess.query(User).options(sa.orm.defer('name'), sa.orm.defer('addresses.email_address')).get(u1.id) assert 'name' not in u1.__dict__ @@ -81,7 +81,7 @@ class PickleTest(_fixtures.FixtureTest): u2 = pickle.loads(pickle.dumps(u1)) sess2 = create_session() - sess2.update(u2) + sess2.add(u2) self.assertEquals(u2.name, 'ed') assert 'addresses' not in u2.__dict__ ad = u2.addresses[0] @@ -132,12 +132,12 @@ class PolymorphicDeferredTest(_base.MappedTest): sess = create_session() sess.add(eu) sess.flush() - sess.clear() + sess.expunge_all() eu = sess.query(User).first() eu2 = pickle.loads(pickle.dumps(eu)) sess2 = create_session() - sess2.update(eu2) + sess2.add(eu2) assert 'email_address' not in eu2.__dict__ self.assertEquals(eu2.email_address, 'foo@bar.com') diff --git a/test/orm/query.py b/test/orm/query.py index 18363ac98..1b56dbb26 100644 --- a/test/orm/query.py +++ b/test/orm/query.py @@ -83,7 +83,7 @@ class GetTest(QueryTest): u = s.query(User).get(7) u2 = s.query(User).get(7) assert u is u2 - s.clear() + s.expunge_all() u2 = s.query(User).get(7) assert u is not u2 @@ -122,7 +122,7 @@ class GetTest(QueryTest): u = s.query(User).populate_existing().get(7) u2 = s.query(User).populate_existing().get(7) assert u is u2 - s.clear() + s.expunge_all() u2 = s.query(User).populate_existing().get(7) assert u is not u2 @@ -893,7 +893,7 @@ class DistinctTest(QueryTest): assert [User(id=7), User(id=9), User(id=8)] == q.all() - sess.clear() + sess.expunge_all() # test that it works on embedded eagerload/LIMIT subquery q = sess.query(User).join('addresses').distinct().options(eagerload('addresses')).order_by(desc(Address.email_address)).limit(2) @@ -1176,7 +1176,7 @@ class JoinTest(QueryTest): l = q.order_by(User.id, AdAlias.id).all() self.assertEquals(l, expected) - sess.clear() + sess.expunge_all() q = sess.query(User).add_entity(AdAlias) l = q.select_from(outerjoin(User, AdAlias)).filter(AdAlias.email_address=='ed@bettyboop.com').all() @@ -1429,7 +1429,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): assert fixtures.user_address_result == l self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): l = q.options(contains_alias('ulist'), contains_eager('addresses')).from_statement(query).all() @@ -1466,14 +1466,14 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): def go(): assert fixtures.user_address_result == q.all() self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() adalias = addresses.alias() q = sess.query(User).select_from(users.outerjoin(adalias)).options(contains_eager(User.addresses, alias=adalias)) def go(): self.assertEquals(fixtures.user_address_result, q.order_by(User.id).all()) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() selectquery = users.outerjoin(addresses).select(users.c.id<10, use_labels=True, order_by=[users.c.id, addresses.c.id]) q = sess.query(User) @@ -1483,13 +1483,13 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): assert fixtures.user_address_result[0:3] == l self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): l = list(q.options(contains_eager(User.addresses)).instances(selectquery.execute())) assert fixtures.user_address_result[0:3] == l self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): l = q.options(contains_eager('addresses')).from_statement(selectquery).all() @@ -1507,7 +1507,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): l = list(q.options(contains_eager('addresses', alias="adalias")).instances(selectquery.execute())) assert fixtures.user_address_result == l self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() # expression.Alias object def go(): @@ -1515,7 +1515,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): assert fixtures.user_address_result == l self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() # Aliased object adalias = aliased(Address) @@ -1523,7 +1523,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): l = q.options(contains_eager('addresses', alias=adalias)).outerjoin((adalias, User.addresses)).order_by(User.id, adalias.id) assert fixtures.user_address_result == l.all() self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() oalias = orders.alias('o1') ialias = items.alias('i1') @@ -1535,14 +1535,14 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): assert fixtures.user_order_result == l self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() # test using Alias with more than one level deep def go(): l = list(q.options(contains_eager('orders', alias=oalias), contains_eager('orders.items', alias=ialias)).instances(query.execute())) assert fixtures.user_order_result == l self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() # test using Aliased with more than one level deep oalias = aliased(Order) @@ -1552,7 +1552,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): outerjoin((oalias, User.orders), (ialias, oalias.items)).order_by(User.id, oalias.id, ialias.id) assert fixtures.user_order_result == l.all() self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def test_mixed_eager_contains_with_limit(self): sess = create_session() @@ -1572,7 +1572,7 @@ class InstancesTest(QueryTest, AssertsCompiledSQL): Order(address_id=None,user_id=7,description=u'order 5',isopen=0,id=5) ])]) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): # same as above, except Order is aliased, so two adapters are applied by the @@ -1849,25 +1849,25 @@ class MixedEntitiesTest(QueryTest): selectquery = users.outerjoin(addresses).select(use_labels=True, order_by=[users.c.id, addresses.c.id]) self.assertEquals(list(sess.query(User, Address).instances(selectquery.execute())), expected) - sess.clear() + sess.expunge_all() for address_entity in (Address, aliased(Address)): q = sess.query(User).add_entity(address_entity).outerjoin(('addresses', address_entity)).order_by(User.id, address_entity.id) self.assertEquals(q.all(), expected) - sess.clear() + sess.expunge_all() q = sess.query(User).add_entity(address_entity) q = q.join(('addresses', address_entity)).filter_by(email_address='ed@bettyboop.com') self.assertEquals(q.all(), [(user8, address3)]) - sess.clear() + sess.expunge_all() q = sess.query(User, address_entity).join(('addresses', address_entity)).filter_by(email_address='ed@bettyboop.com') self.assertEquals(q.all(), [(user8, address3)]) - sess.clear() + sess.expunge_all() q = sess.query(User, address_entity).join(('addresses', address_entity)).options(eagerload('addresses')).filter_by(email_address='ed@bettyboop.com') self.assertEquals(list(util.OrderedSet(q.all())), [(user8, address3)]) - sess.clear() + sess.expunge_all() def test_aliased_multi_mappers(self): sess = create_session() @@ -1888,7 +1888,7 @@ class MixedEntitiesTest(QueryTest): l = q.order_by(User.id, adalias.c.id).all() assert l == expected - sess.clear() + sess.expunge_all() q = sess.query(User).add_entity(Address, alias=adalias) l = q.select_from(users.outerjoin(adalias)).filter(adalias.c.email_address=='ed@bettyboop.com').all() @@ -1901,7 +1901,7 @@ class MixedEntitiesTest(QueryTest): for add_col in (User.name, users.c.name): assert sess.query(User).add_column(add_col).all() == expected - sess.clear() + sess.expunge_all() self.assertRaises(sa_exc.InvalidRequestError, sess.query(User).add_column, object()) @@ -1929,13 +1929,13 @@ class MixedEntitiesTest(QueryTest): q = sess.query(User) q = q.group_by([c for c in users.c]).order_by(User.id).outerjoin('addresses').add_column(func.count(Address.id).label('count')) self.assertEquals(q.all(), expected) - sess.clear() + sess.expunge_all() adalias = aliased(Address) q = sess.query(User) q = q.group_by([c for c in users.c]).order_by(User.id).outerjoin(('addresses', adalias)).add_column(func.count(adalias.id).label('count')) self.assertEquals(q.all(), expected) - sess.clear() + sess.expunge_all() s = select([users, func.count(addresses.c.id).label('count')]).select_from(users.outerjoin(addresses)).group_by(*[c for c in users.c]).order_by(User.id) q = sess.query(User) @@ -1965,7 +1965,7 @@ class MixedEntitiesTest(QueryTest): l = q.add_column("count").add_column("concat").from_statement(s).all() assert l == expected - sess.clear() + sess.expunge_all() # test with select_from() q = create_session().query(User).add_column(func.count(addresses.c.id))\ @@ -1973,21 +1973,21 @@ class MixedEntitiesTest(QueryTest): .group_by([c for c in users.c]).order_by(users.c.id) assert q.all() == expected - sess.clear() + sess.expunge_all() q = create_session().query(User).add_column(func.count(addresses.c.id))\ .add_column(("Name:" + users.c.name)).outerjoin('addresses')\ .group_by([c for c in users.c]).order_by(users.c.id) assert q.all() == expected - sess.clear() + sess.expunge_all() q = create_session().query(User).add_column(func.count(adalias.c.id))\ .add_column(("Name:" + users.c.name)).outerjoin(('addresses', adalias))\ .group_by([c for c in users.c]).order_by(users.c.id) assert q.all() == expected - sess.clear() + sess.expunge_all() class ImmediateTest(_fixtures.FixtureTest): @@ -2191,7 +2191,7 @@ class SelectFromTest(QueryTest): ]) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() sel2 = orders.select(orders.c.id.in_([1,2,3])) self.assertEquals(sess.query(Order).select_from(sel2).join(['items', 'keywords']).filter(Keyword.name == 'red').order_by(Order.id).all(), [ Order(description=u'order 1',id=1), @@ -2220,14 +2220,14 @@ class SelectFromTest(QueryTest): ] ) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): self.assertEquals(sess.query(User).options(eagerload('addresses')).select_from(sel).filter(User.id==8).order_by(User.id).all(), [User(id=8, addresses=[Address(id=2), Address(id=3), Address(id=4)])] ) self.assert_sql_count(testing.db, go, 1) - sess.clear() + sess.expunge_all() def go(): self.assertEquals(sess.query(User).options(eagerload('addresses')).select_from(sel).order_by(User.id)[1], User(id=8, addresses=[Address(id=2), Address(id=3), Address(id=4)])) @@ -2286,7 +2286,7 @@ class SelfReferentialTest(ORMTest): n1.children[1].append(Node(data='n121')) n1.children[1].append(Node(data='n122')) n1.children[1].append(Node(data='n123')) - sess.save(n1) + sess.add(n1) sess.flush() sess.close() @@ -2470,10 +2470,10 @@ class SelfReferentialM2MTest(ORMTest): n2.children = [n3, n6, n7] n3.children = [n5, n4] - sess.save(n1) - sess.save(n2) - sess.save(n3) - sess.save(n4) + sess.add(n1) + sess.add(n2) + sess.add(n3) + sess.add(n4) sess.flush() sess.close() @@ -2548,7 +2548,7 @@ class ExternalColumnsTest(QueryTest): # run the eager version twice to test caching of aliased clauses for x in range(2): - sess.clear() + sess.expunge_all() def go(): self.assertEquals(sess.query(Address).options(eagerload('user')).all(), address_result) self.assert_sql_count(testing.db, go, 1) diff --git a/test/orm/relationships.py b/test/orm/relationships.py index 726933a01..32a5cce1f 100644 --- a/test/orm/relationships.py +++ b/test/orm/relationships.py @@ -160,7 +160,7 @@ class RelationTest2(_base.MappedTest): sess.add_all((c1, c2)) sess.flush() - sess.clear() + sess.expunge_all() test_c1 = sess.query(Company).get(c1.company_id) test_e1 = sess.query(Employee).get([c1.company_id, e1.emp_id]) @@ -206,7 +206,7 @@ class RelationTest2(_base.MappedTest): sess.add_all((c1, c2)) sess.flush() - sess.clear() + sess.expunge_all() test_c1 = sess.query(Company).get(c1.company_id) test_e1 = sess.query(Employee).get([c1.company_id, e1.emp_id]) @@ -344,14 +344,14 @@ class RelationTest3(_base.MappedTest): s.flush() - s.clear() + s.expunge_all() j = s.query(Job).filter_by(jobno=u'somejob').one() oldp = list(j.pages) j.pages = [] s.flush() - s.clear() + s.expunge_all() j = s.query(Job).filter_by(jobno=u'somejob2').one() j.pages[1].current_version = 12 s.delete(j) @@ -466,7 +466,7 @@ class RelationTest4(_base.MappedTest): sess.flush() assert a1 not in sess assert b1 not in sess - sess.clear() + sess.expunge_all() sa.orm.clear_mappers() @testing.resolve_artifact_names @@ -491,7 +491,7 @@ class RelationTest4(_base.MappedTest): sess.flush() assert a1 not in sess assert b1 not in sess - sess.clear() + sess.expunge_all() sa.orm.clear_mappers() @testing.resolve_artifact_names @@ -513,7 +513,7 @@ class RelationTest4(_base.MappedTest): sess.flush() assert a1 not in sess assert b1 not in sess - sess.clear() + sess.expunge_all() @testing.resolve_artifact_names def test_delete_manual_BtoA(self): @@ -591,7 +591,7 @@ class RelationTest5(_base.MappedTest): con.lineItems.append(li) session.add(li) session.flush() - session.clear() + session.expunge_all() newcon = session.query(Container).first() assert con.policyNum == newcon.policyNum assert len(newcon.lineItems) == 10 @@ -639,7 +639,7 @@ class RelationTest6(_base.MappedTest): t1.foo.append(TagInstance(data='not_iplc_case')) sess.add(t1) sess.flush() - sess.clear() + sess.expunge_all() # relation works eq_(sess.query(Tag).all(), [Tag(data='some tag', foo=[TagInstance(data='iplc_case')])]) @@ -1010,7 +1010,7 @@ class ViewOnlyOverlappingNames(_base.MappedTest): sess.add(c1) sess.add(c3) sess.flush() - sess.clear() + sess.expunge_all() c1 = sess.query(C1).get(c1.id) assert set([x.id for x in c1.t2s]) == set([c2a.id, c2b.id]) @@ -1068,7 +1068,7 @@ class ViewOnlyUniqueNames(_base.MappedTest): sess.add_all((c1, c3)) sess.flush() - sess.clear() + sess.expunge_all() c1 = sess.query(C1).get(c1.t1id) assert set([x.t2id for x in c1.t2s]) == set([c2a.t2id, c2b.t2id]) @@ -1188,7 +1188,7 @@ class ViewOnlyRepeatedRemoteColumn(_base.MappedTest): sess.add_all((f1, f2)) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(Foo).filter_by(id=f1.id).one(), Foo(bars=[Bar(data='b1'), Bar(data='b2')])) eq_(sess.query(Foo).filter_by(id=f2.id).one(), @@ -1235,7 +1235,7 @@ class ViewOnlyRepeatedLocalColumn(_base.MappedTest): sess.add_all((b1, b2, b3, b4)) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(Foo).filter_by(id=f1.id).one(), Foo(bars=[Bar(data='b1'), Bar(data='b2'), Bar(data='b4')])) eq_(sess.query(Foo).filter_by(id=f2.id).one(), @@ -1286,7 +1286,7 @@ class ViewOnlyComplexJoin(_base.MappedTest): sess = create_session() sess.add(T2(data='t2', t1=T1(data='t1'), t3s=[T3(data='t3')])) sess.flush() - sess.clear() + sess.expunge_all() a = sess.query(T1).first() eq_(a.t3s, [T3(data='t3')]) @@ -1348,7 +1348,7 @@ class ExplicitLocalRemoteTest(_base.MappedTest): b3 = T2(data='b3', t1id='Number2') sess.add_all((a1, a2, b1, b2, b3)) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(T1).first(), T1(id='number1', data='a1', t2s=[ @@ -1373,7 +1373,7 @@ class ExplicitLocalRemoteTest(_base.MappedTest): b3 = T2(data='b3', t1id='Number2') sess.add_all((a1, a2, b1, b2, b3)) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(T2).filter(T2.data.in_(['b1', 'b2'])).all(), [T2(data='b1', t1=[T1(id='number1', data='a1')]), @@ -1396,7 +1396,7 @@ class ExplicitLocalRemoteTest(_base.MappedTest): b3 = T2(data='b2', t1id='number2') sess.add_all((a1, a2, b1, b2, b3)) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(T1).first(), T1(id='NuMbeR1', data='a1', t2s=[ @@ -1420,7 +1420,7 @@ class ExplicitLocalRemoteTest(_base.MappedTest): b3 = T2(data='b3', t1id='number2') sess.add_all((a1, a2, b1, b2, b3)) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(T2).filter(T2.data.in_(['b1', 'b2'])).all(), [T2(data='b1', t1=[T1(id='NuMbeR1', data='a1')]), diff --git a/test/orm/scoping.py b/test/orm/scoping.py index eea855490..bdfc5a9d5 100644 --- a/test/orm/scoping.py +++ b/test/orm/scoping.py @@ -105,7 +105,7 @@ class ScopedMapperTest(_ScopedTest): sso = SomeOtherObject() s.options.append(sso) Session.flush() - Session.clear() + Session.expunge_all() @testing.resolve_artifact_names def test_query(self): @@ -225,7 +225,7 @@ class ScopedMapperTest2(_ScopedTest): b = BaseClass(data='b1') s = SubClass(data='s1', somedata='somedata') Session.commit() - Session.clear() + Session.expunge_all() eq_(expunge_list([BaseClass(data='b1'), SubClass(data='s1', somedata='somedata')]), diff --git a/test/orm/selectable.py b/test/orm/selectable.py index 1e4527e6b..74c41c852 100644 --- a/test/orm/selectable.py +++ b/test/orm/selectable.py @@ -37,7 +37,7 @@ class SelectableNoFromsTest(_base.MappedTest): sess = create_session(bind=testing.db) sess.add(Subset(data=1)) sess.flush() - sess.clear() + sess.expunge_all() eq_(sess.query(Subset).all(), [Subset(data=1)]) eq_(sess.query(Subset).filter(Subset.data==1).one(), Subset(data=1)) diff --git a/test/orm/session.py b/test/orm/session.py index 180ef745d..e1eaf82cf 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -648,6 +648,7 @@ class SessionTest(_fixtures.FixtureTest): assert c.scalar("select count(1) from users") == 1 + @testing.uses_deprecated() @engines.close_open_connections @testing.resolve_artifact_names def test_save_update_delete(self): @@ -671,19 +672,19 @@ class SessionTest(_fixtures.FixtureTest): # modify outside of session, assert changes remain/get saved user.name = "fred" - s.update(user) + s.add(user) assert user in s assert user in s.dirty s.flush() - s.clear() + s.expunge_all() assert s.query(User).count() == 1 user = s.query(User).one() assert user.name == 'fred' # ensure its not dirty if no changes occur - s.clear() + s.expunge_all() assert user not in s - s.update(user) + s.add(user) assert user in s assert user not in s.dirty @@ -716,7 +717,7 @@ class SessionTest(_fixtures.FixtureTest): u = User(name='fred') s.add(u) s.flush() - s.clear() + s.expunge_all() user = s.query(User).one() assert user not in s.dirty @@ -858,7 +859,7 @@ class SessionTest(_fixtures.FixtureTest): assert a not in s s.flush() print "\n".join([repr(x.__dict__) for x in s]) - s.clear() + s.expunge_all() assert s.query(User).one().id == u.id assert s.query(Address).first() is None @@ -878,7 +879,7 @@ class SessionTest(_fixtures.FixtureTest): assert u not in s assert a in s s.flush() - s.clear() + s.expunge_all() assert s.query(Address).one().id == a.id assert s.query(User).first() is None @@ -1017,7 +1018,7 @@ class SessionTest(_fixtures.FixtureTest): sess.add(User(name='u2')) sess.flush() - sess.clear() + sess.expunge_all() self.assertEquals(sess.query(User).order_by(User.name).all(), [ User(name='u1 modified'), @@ -1073,7 +1074,7 @@ class SessionTest(_fixtures.FixtureTest): assert u2 is not None and u2 is not u1 assert u2 in sess - self.assertRaises(Exception, lambda: sess.update(u1)) + self.assertRaises(Exception, lambda: sess.add(u1)) sess.expunge(u2) assert u2 not in sess @@ -1082,13 +1083,13 @@ class SessionTest(_fixtures.FixtureTest): u1.name = "John" u2.name = "Doe" - sess.update(u1) + sess.add(u1) assert u1 in sess assert Session.object_session(u1) is sess sess.flush() - sess.clear() + sess.expunge_all() u3 = sess.query(User).get(u1.id) assert u3 is not u1 and u3 is not u2 and u3.name == u1.name @@ -1173,7 +1174,7 @@ class DisposedStates(testing.ORMTest): self._test_session().flush() def test_clear(self): - self._test_session().clear() + self._test_session().expunge_all() def test_close(self): self._test_session().close() @@ -1217,6 +1218,7 @@ class SessionInterface(testing.TestBase): return mapper(cls, Table('t', sa.MetaData(), Column('id', Integer, primary_key=True))) + @testing.uses_deprecated() def _test_instance_guards(self, user_arg): watchdog = set() diff --git a/test/orm/sharding/shard.py b/test/orm/sharding/shard.py index 63f6932ea..10aaee131 100644 --- a/test/orm/sharding/shard.py +++ b/test/orm/sharding/shard.py @@ -138,10 +138,10 @@ class ShardTest(TestBase): sess = create_session() for c in [tokyo, newyork, toronto, london, dublin, brasilia, quito]: - sess.save(c) + sess.add(c) sess.commit() tokyo.city # reload 'city' attribute on tokyo - sess.clear() + sess.expunge_all() eq_(db2.execute(weather_locations.select()).fetchall(), [(1, 'Asia', 'Tokyo')]) eq_(db1.execute(weather_locations.select()).fetchall(), [(2, 'North America', 'New York'), (3, 'North America', 'Toronto')]) diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index bb84bfd5b..7a8415cdc 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -42,7 +42,7 @@ class HistoryTest(_fixtures.FixtureTest): self.assert_(u.addresses == [a]) session.commit() - session.clear() + session.expunge_all() u = session.query(m).one() assert u.addresses[0].user == u @@ -252,23 +252,23 @@ class UnicodeSchemaTest(engine_base.AltEngineTest, _base.MappedTest): session = create_session() session.add(a1) session.flush() - session.clear() + session.expunge_all() new_a1 = session.query(A).filter(t1.c.a == a1.a).one() assert new_a1.a == a1.a assert new_a1.t2s[0].d == b1.d - session.clear() + session.expunge_all() new_a1 = (session.query(A).options(sa.orm.eagerload('t2s')). filter(t1.c.a == a1.a)).one() assert new_a1.a == a1.a assert new_a1.t2s[0].d == b1.d - session.clear() + session.expunge_all() new_a1 = session.query(A).filter(A.a == a1.a).one() assert new_a1.a == a1.a assert new_a1.t2s[0].d == b1.d - session.clear() + session.expunge_all() @testing.fails_on('mssql', 'pyodbc returns a non unicode encoding of the results description.') @testing.resolve_artifact_names @@ -290,7 +290,7 @@ class UnicodeSchemaTest(engine_base.AltEngineTest, _base.MappedTest): session = create_session() session.add_all((a1, b1)) session.flush() - session.clear() + session.expunge_all() eq_([A(b=5), B(e=7)], session.query(A).all()) @@ -322,7 +322,7 @@ class MutableTypesTest(_base.MappedTest): session = create_session() session.add(f1) session.flush() - session.clear() + session.expunge_all() f2 = session.query(Foo).filter_by(id=f1.id).one() assert 'data' in sa.orm.attributes.instance_state(f2).unmodified @@ -332,7 +332,7 @@ class MutableTypesTest(_base.MappedTest): assert f2 in session.dirty assert 'data' not in sa.orm.attributes.instance_state(f2).unmodified session.flush() - session.clear() + session.expunge_all() f3 = session.query(Foo).filter_by(id=f1.id).one() ne_(f3.data,f1.data) @@ -403,7 +403,7 @@ class MutableTypesTest(_base.MappedTest): session = create_session(autocommit=False) session.add(f1) session.commit() - session.clear() + session.expunge_all() f1 = session.query(Foo).get(f1.id) f1.val = u'hi' @@ -474,7 +474,7 @@ class PickledDicts(_base.MappedTest): f1.data[0]['personne']['VenSoir']= False self.sql_count_(1, session.commit) - session.clear() + session.expunge_all() f = session.query(Foo).get(f1.id) eq_(f.data, [ { @@ -530,7 +530,7 @@ class PKTest(_base.MappedTest): session = create_session() session.add(e) session.flush() - session.clear() + session.expunge_all() e2 = session.query(Entry).get((e.multi_id, 2)) self.assert_(e is not e2) @@ -655,7 +655,7 @@ class ClauseAttributesTest(_base.MappedTest): assert (u.counter == 2) is True self.sql_count_(1, go) - session.clear() + session.expunge_all() u = session.query(User).get(u.id) eq_(u.name, 'test2') eq_(u.counter, 2) @@ -711,7 +711,7 @@ class PassiveDeletesTest(_base.MappedTest): session.add(mc) session.flush() - session.clear() + session.expunge_all() assert myothertable.count().scalar() == 4 mc = session.query(MyClass).get(mc.id) @@ -801,7 +801,7 @@ class ExtraPassiveDeletesTest(_base.MappedTest): mc.children.append(MyOtherClass()) session.add(mc) session.flush() - session.clear() + session.expunge_all() assert myothertable.count().scalar() == 4 mc = session.query(MyClass).get(mc.id) @@ -821,7 +821,7 @@ class ExtraPassiveDeletesTest(_base.MappedTest): mc.children.append(MyOtherClass()) session.add(mc) session.flush() - session.clear() + session.expunge_all() assert myothertable.count().scalar() == 1 @@ -922,7 +922,7 @@ class DefaultTest(_base.MappedTest): self.assert_(h5.foober == 'im the new foober') self.sql_count_(0, go) - session.clear() + session.expunge_all() (h1, h2, h3, h4, h5) = session.query(Hoho).order_by(Hoho.id).all() @@ -995,7 +995,7 @@ class DefaultTest(_base.MappedTest): session = create_session() session.add(h1) session.flush() - session.clear() + session.expunge_all() eq_(session.query(Hoho).get(h1.id), Hoho(hoho=hohoval, @@ -1005,7 +1005,7 @@ class DefaultTest(_base.MappedTest): h1 = session.query(Hoho).get(h1.id) h1.secondaries.append(Secondary(data='s2')) session.flush() - session.clear() + session.expunge_all() eq_(session.query(Hoho).get(h1.id), Hoho(hoho=hohoval, @@ -1189,7 +1189,7 @@ class OneToManyTest(_fixtures.FixtureTest): session.delete(u1) session.flush() - session.clear() + session.expunge_all() u2 = session.query(User).get(u2.id) eq_(len(u2.addresses), 1) @@ -1212,7 +1212,7 @@ class OneToManyTest(_fixtures.FixtureTest): u2.addresses.append(a) session.flush() - session.clear() + session.expunge_all() u2 = session.query(User).get(u2.id) eq_(len(u2.addresses), 1) @@ -1317,7 +1317,7 @@ class SaveTest(_fixtures.FixtureTest): assert u is nu # clear out the identity map, so next get forces a SELECT - session.clear() + session.expunge_all() # check it again, identity should be different but ids the same nu = session.query(m).get(u.id) @@ -1325,7 +1325,7 @@ class SaveTest(_fixtures.FixtureTest): # change first users name and save session = create_session() - session.update(u) + session.add(u) u.name = 'modifiedname' assert u in session.dirty session.flush() @@ -1358,7 +1358,7 @@ class SaveTest(_fixtures.FixtureTest): session = create_session() session.add(u) session.flush() - session.clear() + session.expunge_all() u = session.query(SUser).first() eq_(u.syn_name, 'User:some name:User') @@ -1383,7 +1383,7 @@ class SaveTest(_fixtures.FixtureTest): session = create_session() session.add(u) session.flush() - session.clear() + session.expunge_all() u = session.query(User).one() u.name = 'newname' @@ -1407,7 +1407,7 @@ class SaveTest(_fixtures.FixtureTest): session = create_session() session.add(au) session.flush() - session.clear() + session.expunge_all() rt = session.query(AddressUser).one() eq_(au.user_id, rt.user_id) @@ -1432,7 +1432,7 @@ class SaveTest(_fixtures.FixtureTest): eq_(list(session.execute(orders.select(), mapper=Order)), [(42, None, None, 'foo', None)]) - session.clear() + session.expunge_all() # assert that a set operation doesn't trigger a load operation o = session.query(Order).filter(Order.description == 'foo').one() @@ -1444,7 +1444,7 @@ class SaveTest(_fixtures.FixtureTest): eq_(list(session.execute(orders.select(), mapper=Order)), [(42, None, None, 'hoho', None)]) - session.clear() + session.expunge_all() # test assigning None to an unloaded deferred also works o = session.query(Order).filter(Order.description == 'hoho').one() @@ -1465,7 +1465,7 @@ class SaveTest(_fixtures.FixtureTest): session = create_session() session.add(u) session.flush() - session.clear() + session.expunge_all() u = session.query(User).get(u.id) u.name = '' @@ -1490,7 +1490,7 @@ class SaveTest(_fixtures.FixtureTest): session = create_session() session.add(u) session.flush() - session.clear() + session.expunge_all() id = m.primary_key_from_instance(u) @@ -1511,7 +1511,7 @@ class SaveTest(_fixtures.FixtureTest): address_rows = addresses.select(addresses.c.id.in_([u.id])).execute().fetchall() eq_(address_rows[0].values(), [u.id, u.foo_id, 'lala@hey.com']) - session.clear() + session.expunge_all() u = session.query(User).get(id) assert u.name == 'imnew' @@ -1528,7 +1528,7 @@ class SaveTest(_fixtures.FixtureTest): session = create_session() session.add(u) session.flush() - session.clear() + session.expunge_all() u = session.query(User).get(u.id) session.delete(u) @@ -1565,7 +1565,7 @@ class SaveTest(_fixtures.FixtureTest): # test insert ordering is maintained assert names == ['user1', 'user2', 'user4', 'user5', 'user3'] - session.clear() + session.expunge_all() sa.orm.clear_mappers() @@ -1643,7 +1643,7 @@ class ManyToOneTest(_fixtures.FixtureTest): session = create_session() session.add(a1) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Address).get(a1.id) u1 = session.query(User).get(u1.id) @@ -1651,7 +1651,7 @@ class ManyToOneTest(_fixtures.FixtureTest): a1.user = None session.flush() - session.clear() + session.expunge_all() a1 = session.query(Address).get(a1.id) u1 = session.query(User).get(u1.id) assert a1.user is None @@ -1669,7 +1669,7 @@ class ManyToOneTest(_fixtures.FixtureTest): session = create_session() session.add_all((a1, a2)) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Address).get(a1.id) a2 = session.query(Address).get(a2.id) @@ -1679,7 +1679,7 @@ class ManyToOneTest(_fixtures.FixtureTest): a1.user = None a2.user = u1 session.flush() - session.clear() + session.expunge_all() a1 = session.query(Address).get(a1.id) a2 = session.query(Address).get(a2.id) @@ -1700,7 +1700,7 @@ class ManyToOneTest(_fixtures.FixtureTest): session = create_session() session.add_all((a1, u1, u2)) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Address).get(a1.id) u1 = session.query(User).get(u1.id) @@ -1709,7 +1709,7 @@ class ManyToOneTest(_fixtures.FixtureTest): a1.user = u2 session.flush() - session.clear() + session.expunge_all() a1 = session.query(Address).get(a1.id) u1 = session.query(User).get(u1.id) u2 = session.query(User).get(u2.id) @@ -1729,13 +1729,13 @@ class ManyToOneTest(_fixtures.FixtureTest): session = create_session() session.add(u1) session.flush() - session.clear() + session.expunge_all() a1 = session.query(Address).get(a1.id) a1.user = None session.flush() - session.clear() + session.expunge_all() assert session.query(Address).get(a1.id).user is None assert session.query(User).get(u1.id).addresses == [] @@ -1916,7 +1916,7 @@ class ManyToManyTest(_fixtures.FixtureTest): item.keywords.append(k2) session.flush() - session.clear() + session.expunge_all() item = session.query(Item).get(item.id) assert item.keywords == [k1, k2] @@ -2076,13 +2076,13 @@ class BooleanColTest(_base.MappedTest): for clear in (False, True): if clear: - sess.clear() + sess.expunge_all() eq_(sess.query(T).all(), [T(value=True, name="t1"), T(value=False, name="t2"), T(value=True, name="t3")]) if clear: - sess.clear() + sess.expunge_all() eq_(sess.query(T).filter(T.value==True).all(), [T(value=True, name="t1"),T(value=True, name="t3")]) if clear: - sess.clear() + sess.expunge_all() eq_(sess.query(T).filter(T.value==False).all(), [T(value=False, name="t2")]) t2 = sess.query(T).get(t2.id) |