mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-06-04 06:48:27 -04:00
- session.refresh() raises an informative error message if
the list of attributes does not include any column-based attributes. - query() raises an informative error message if no columns or mappers are specified. - lazy loaders now trigger autoflush before proceeding. This allows expire() of a collection or scalar relation to function properly in the context of autoflush. - whitespace fix to new Table prefixes option
This commit is contained in:
+39
-1
@@ -3,7 +3,7 @@
|
||||
import testenv; testenv.configure_for_tests()
|
||||
import gc
|
||||
from testlib import sa, testing
|
||||
from testlib.sa import Table, Column, Integer, String, ForeignKey
|
||||
from testlib.sa import Table, Column, Integer, String, ForeignKey, exc as sa_exc
|
||||
from testlib.sa.orm import mapper, relation, create_session, attributes
|
||||
from orm import _base, _fixtures
|
||||
|
||||
@@ -98,6 +98,44 @@ class ExpireTest(_fixtures.FixtureTest):
|
||||
# but now its back, rollback has occured, the _remove_newly_deleted
|
||||
# is reverted
|
||||
self.assertEquals(u.name, 'chuck')
|
||||
|
||||
@testing.resolve_artifact_names
|
||||
def test_lazyload_autoflushes(self):
|
||||
mapper(User, users, properties={
|
||||
'addresses':relation(Address, order_by=addresses.c.email_address)
|
||||
})
|
||||
mapper(Address, addresses)
|
||||
s = create_session(autoflush=True, autocommit=False)
|
||||
u = s.query(User).get(8)
|
||||
adlist = u.addresses
|
||||
self.assertEquals(adlist, [
|
||||
Address(email_address='ed@bettyboop.com'),
|
||||
Address(email_address='ed@lala.com'),
|
||||
Address(email_address='ed@wood.com'),
|
||||
])
|
||||
a1 = u.addresses[2]
|
||||
a1.email_address = 'aaaaa'
|
||||
s.expire(u, ['addresses'])
|
||||
self.assertEquals(u.addresses, [
|
||||
Address(email_address='aaaaa'),
|
||||
Address(email_address='ed@bettyboop.com'),
|
||||
Address(email_address='ed@lala.com'),
|
||||
])
|
||||
|
||||
@testing.resolve_artifact_names
|
||||
def test_refresh_collection_exception(self):
|
||||
"""test graceful failure for currently unsupported immediate refresh of a collection"""
|
||||
|
||||
mapper(User, users, properties={
|
||||
'addresses':relation(Address, order_by=addresses.c.email_address)
|
||||
})
|
||||
mapper(Address, addresses)
|
||||
s = create_session(autoflush=True, autocommit=False)
|
||||
u = s.query(User).get(8)
|
||||
self.assertRaisesMessage(sa_exc.InvalidRequestError, "properties specified for refresh", s.refresh, u, ['addresses'])
|
||||
|
||||
# in contrast to a regular query with no columns
|
||||
self.assertRaisesMessage(sa_exc.InvalidRequestError, "no columns with which to SELECT", s.query().all)
|
||||
|
||||
@testing.resolve_artifact_names
|
||||
def test_refresh_cancels_expire(self):
|
||||
|
||||
@@ -81,6 +81,9 @@ class AutoExpireTest(TransactionTest):
|
||||
s.add(u1)
|
||||
s.commit()
|
||||
|
||||
# this actually tests that the delete() operation,
|
||||
# when cascaded to the "addresses" collection, does not
|
||||
# trigger a flush (via lazyload) before the cascade is complete.
|
||||
s.delete(u1)
|
||||
assert u1 in s.deleted
|
||||
s.rollback()
|
||||
|
||||
Reference in New Issue
Block a user