diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-02-22 23:17:15 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-02-22 23:17:15 +0000 |
commit | bb6ec17708e56170bcccf7e32703d0ba37b160d2 (patch) | |
tree | 1da7768491154707db045c235f1ba6f2170a02e7 /test | |
parent | e203b4dd4e2ce24e18fbeb9db515b2bdbbb56bc5 (diff) | |
download | sqlalchemy-bb6ec17708e56170bcccf7e32703d0ba37b160d2.tar.gz |
- the value of a bindparam() can be a callable, in which
case it's evaluated at statement execution time to
get the value.
- expressions used in filter(), filter_by() and others,
when they make usage of a clause generated from a
relation using the identity of a child object
(e.g. filter(Parent.child==<somechild>)), evaluate
the actual primary key value of <somechild> at
execution time so that the autoflush step of the
Query can complete, thereby populating the PK value
of <somechild> in the case that <somechild> was
pending.
- cleanup of attributes.get_committed_value() to never return
the NO_VALUE value; evaluates to None
Diffstat (limited to 'test')
-rw-r--r-- | test/orm/attributes.py | 20 | ||||
-rw-r--r-- | test/orm/session.py | 15 |
2 files changed, 35 insertions, 0 deletions
diff --git a/test/orm/attributes.py b/test/orm/attributes.py index 27860517c..bfb4d0d77 100644 --- a/test/orm/attributes.py +++ b/test/orm/attributes.py @@ -597,6 +597,26 @@ class DeferredBackrefTest(TestBase): lazy_load = (p1, p2, p3) = [Post("post 1"), Post("post 2"), Post("post 3")] class HistoryTest(TestBase): + def test_get_committed_value(self): + class Foo(fixtures.Base): + pass + + attributes.register_class(Foo) + attributes.register_attribute(Foo, 'someattr', uselist=False, useobject=False) + + f = Foo() + self.assertEquals(Foo.someattr.impl.get_committed_value(f._state), None) + + f.someattr = 3 + self.assertEquals(Foo.someattr.impl.get_committed_value(f._state), None) + + f = Foo() + f.someattr = 3 + self.assertEquals(Foo.someattr.impl.get_committed_value(f._state), None) + + f._state.commit(['someattr']) + self.assertEquals(Foo.someattr.impl.get_committed_value(f._state), 3) + def test_scalar(self): class Foo(fixtures.Base): pass diff --git a/test/orm/session.py b/test/orm/session.py index a1c850073..1d6742d8a 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -140,6 +140,21 @@ class SessionTest(TestBase, AssertsExecutionResults): assert testing.db.connect().execute("select count(1) from users").scalar() == 1 sess.close() + def test_autoflush_expressions(self): + class User(fixtures.Base): + pass + class Address(fixtures.Base): + pass + mapper(User, users, properties={ + 'addresses':relation(Address, backref="user") + }) + mapper(Address, addresses) + + sess = create_session(autoflush=True, transactional=True) + u = User(user_name='ed', addresses=[Address(email_address='foo')]) + sess.save(u) + self.assertEquals(sess.query(Address).filter(Address.user==u).one(), Address(email_address='foo')) + @testing.unsupported('sqlite', 'mssql') # TEMP: test causes mssql to hang @engines.close_open_connections def test_autoflush_unbound(self): |