]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added unittest for orm-persisted insert without a postfetch, tweak to engine to only...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 Mar 2006 21:10:20 +0000 (21:10 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 Mar 2006 21:10:20 +0000 (21:10 +0000)
lib/sqlalchemy/engine.py
test/objectstore.py

index 5f681d39e907fe544681efcb915ba3aed1f038c8..518ea8a15c5ba2440ac132970c989802a6acd654 100644 (file)
@@ -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
index a4d2e874cb8dc285d4b666feb5bc26ba54082424..affa32a5f84875e5868ab42f9f18320cf12ced3b 100644 (file)
@@ -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)