summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-12-14 12:17:56 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-12-14 12:17:56 -0500
commit5adc08b42f98904912c4016b319720fd14be51ac (patch)
tree9cafbcf7949ab7cda2c8b2b8c13b7a4b293ac4e5
parentc59ea573e12e94760e2e8770ebf5e9690e9c0105 (diff)
downloadsqlalchemy-ticket_3609.tar.gz
-rw-r--r--lib/sqlalchemy/orm/persistence.py1
-rw-r--r--lib/sqlalchemy/testing/assertsql.py2
-rw-r--r--test/orm/test_unitofworkv2.py150
3 files changed, 109 insertions, 44 deletions
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py
index 9b631d2b0..4ac7b5538 100644
--- a/lib/sqlalchemy/orm/persistence.py
+++ b/lib/sqlalchemy/orm/persistence.py
@@ -750,6 +750,7 @@ def _emit_insert_statements(base_mapper, uowtransaction,
bool(rec[5]), # whether we have "value" parameters
rec[6],
rec[7])):
+
if not bookkeeping or \
(
has_all_defaults
diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py
index ce01e9b81..397e62338 100644
--- a/lib/sqlalchemy/testing/assertsql.py
+++ b/lib/sqlalchemy/testing/assertsql.py
@@ -70,7 +70,7 @@ class CompiledSQL(SQLMatchRule):
def _compile_dialect(self, execute_observed):
if self.dialect == 'default':
- return DefaultDialect(implicit_returning=True)
+ return DefaultDialect()
else:
# ugh
if self.dialect == 'postgresql':
diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py
index 126b95082..8fd1df148 100644
--- a/test/orm/test_unitofworkv2.py
+++ b/test/orm/test_unitofworkv2.py
@@ -1910,7 +1910,7 @@ class EagerDefaultsTest(fixtures.MappedTest):
self.assert_sql_count(testing.db, go, 0)
- def test_insert_defaults_non_present(self):
+ def test_insert_defaults_nonpresent(self):
Thing = self.classes.Thing
s = Session()
@@ -1921,20 +1921,40 @@ class EagerDefaultsTest(fixtures.MappedTest):
s.add_all([t1, t2])
- self.assert_sql_execution(
- testing.db,
- s.commit,
- CompiledSQL(
- "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
- [{'id': 1}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
- [{'id': 2}],
- dialect='postgresql'
- ),
- )
+ if testing.db.dialect.implicit_returning:
+ self.assert_sql_execution(
+ testing.db,
+ s.commit,
+ CompiledSQL(
+ "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
+ [{'id': 1}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
+ [{'id': 2}],
+ dialect='postgresql'
+ ),
+ )
+ else:
+ self.assert_sql_execution(
+ testing.db,
+ s.commit,
+ CompiledSQL(
+ "INSERT INTO test (id) VALUES (:id)",
+ [{'id': 1}, {'id': 2}]
+ ),
+ CompiledSQL(
+ "SELECT test.foo AS test_foo FROM test "
+ "WHERE test.id = :param_1",
+ [{'param_1': 1}]
+ ),
+ CompiledSQL(
+ "SELECT test.foo AS test_foo FROM test "
+ "WHERE test.id = :param_1",
+ [{'param_1': 2}]
+ )
+ )
def test_update_defaults_nonpresent(self):
Thing2 = self.classes.Thing2
@@ -1957,34 +1977,78 @@ class EagerDefaultsTest(fixtures.MappedTest):
t4.foo = 8
t4.bar = 12
- self.assert_sql_execution(
- testing.db,
- s.commit,
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s WHERE test2.id = %(test2_id)s "
- "RETURNING test2.bar",
- [{'foo': 5, 'test2_id': 1}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
- "WHERE test2.id = %(test2_id)s",
- [{'foo': 6, 'bar': 10, 'test2_id': 2}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s WHERE test2.id = %(test2_id)s "
- "RETURNING test2.bar",
- [{'foo': 7, 'test2_id': 3}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
- "WHERE test2.id = %(test2_id)s",
- [{'foo': 8, 'bar': 12, 'test2_id': 4}],
- dialect='postgresql'
- ),
- )
+ if testing.db.dialect.implicit_returning:
+ self.assert_sql_execution(
+ testing.db,
+ s.flush,
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s "
+ "WHERE test2.id = %(test2_id)s "
+ "RETURNING test2.bar",
+ [{'foo': 5, 'test2_id': 1}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
+ "WHERE test2.id = %(test2_id)s",
+ [{'foo': 6, 'bar': 10, 'test2_id': 2}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s "
+ "WHERE test2.id = %(test2_id)s "
+ "RETURNING test2.bar",
+ [{'foo': 7, 'test2_id': 3}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
+ "WHERE test2.id = %(test2_id)s",
+ [{'foo': 8, 'bar': 12, 'test2_id': 4}],
+ dialect='postgresql'
+ ),
+ )
+ else:
+ self.assert_sql_execution(
+ testing.db,
+ s.flush,
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo WHERE test2.id = :test2_id",
+ [{'foo': 5, 'test2_id': 1}]
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo, bar=:bar "
+ "WHERE test2.id = :test2_id",
+ [{'foo': 6, 'bar': 10, 'test2_id': 2}],
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo WHERE test2.id = :test2_id",
+ [{'foo': 7, 'test2_id': 3}]
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo, bar=:bar "
+ "WHERE test2.id = :test2_id",
+ [{'foo': 8, 'bar': 12, 'test2_id': 4}],
+ ),
+ CompiledSQL(
+ "SELECT test2.bar AS test2_bar FROM test2 "
+ "WHERE test2.id = :param_1",
+ [{'param_1': 1}]
+ ),
+ CompiledSQL(
+ "SELECT test2.bar AS test2_bar FROM test2 "
+ "WHERE test2.id = :param_1",
+ [{'param_1': 3}]
+ )
+ )
+
+ def go():
+ eq_(t1.bar, 2)
+ eq_(t2.bar, 10)
+ eq_(t3.bar, 4)
+ eq_(t4.bar, 12)
+
+ self.assert_sql_count(testing.db, go, 0)
def test_update_defaults_present(self):
Thing2 = self.classes.Thing2