From: Mike Bayer Date: Sun, 5 Mar 2006 21:10:20 +0000 (+0000) Subject: added unittest for orm-persisted insert without a postfetch, tweak to engine to only... X-Git-Tag: rel_0_1_4~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d54b5eba74bd5569fa3c89ba730957177c6b11f6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added unittest for orm-persisted insert without a postfetch, tweak to engine to only signal postfetch if the passivedefault columns received None/NULL for their parameter (since they dont exec otherwise) --- diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py index 5f681d39e9..518ea8a15c 100644 --- a/lib/sqlalchemy/engine.py +++ b/lib/sqlalchemy/engine.py @@ -468,9 +468,9 @@ class SQLEngine(schema.SchemaEngine): last_inserted_ids = [] need_lastrowid=False for c in compiled.statement.table.c: - if isinstance(c.default, schema.PassiveDefault): - self.context.lastrow_has_defaults = True if not param.has_key(c.name) or param[c.name] is None: + if isinstance(c.default, schema.PassiveDefault): + self.context.lastrow_has_defaults = True newid = drunner.get_column_default(c) if newid is not None: param[c.name] = newid diff --git a/test/objectstore.py b/test/objectstore.py index a4d2e874cb..affa32a5f8 100644 --- a/test/objectstore.py +++ b/test/objectstore.py @@ -213,6 +213,9 @@ class PKTest(AssertMixin): objectstore.commit() class DefaultTest(AssertMixin): + """tests that when saving objects whose table contains DefaultGenerators, either python-side, preexec or database-side, + the newly saved instances receive all the default values either through a post-fetch or getting the pre-exec'ed + defaults back from the engine.""" def setUpAll(self): #db.echo = 'debug' use_string_defaults = db.engine.__module__.endswith('postgres') or db.engine.__module__.endswith('oracle') or db.engine.__module__.endswith('sqlite') @@ -236,8 +239,7 @@ class DefaultTest(AssertMixin): self.table.drop() def setUp(self): self.table = Table('default_test', db) - def testbasic(self): - + def testinsert(self): class Hoho(object):pass assign_mapper(Hoho, self.table) h1 = Hoho(hoho=self.althohoval) @@ -264,6 +266,16 @@ class DefaultTest(AssertMixin): self.assert_(h2.foober == h3.foober == h4.foober == 'im foober') self.assert_(h5.foober=='im the new foober') + def testinsertnopostfetch(self): + # populates the PassiveDefaults explicitly so there is no "post-update" + class Hoho(object):pass + assign_mapper(Hoho, self.table) + h1 = Hoho(hoho="15", counter="15") + objectstore.commit() + self.assert_(h1.hoho=="15") + self.assert_(h1.counter=="15") + self.assert_(h1.foober=="im foober") + def testupdate(self): class Hoho(object):pass assign_mapper(Hoho, self.table)