]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The version_id_col feature on mapper() will raise a warning when
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 18 Dec 2009 19:11:19 +0000 (19:11 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 18 Dec 2009 19:11:19 +0000 (19:11 +0000)
used with dialects that don't support "rowcount" adequately.
[ticket:1569]

CHANGES
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/orm/mapper.py
test/orm/test_unitofwork.py

diff --git a/CHANGES b/CHANGES
index bebcf8043dcfaf41ed0317af275c6d8fe66cf8f4..154c22a29a426fd3e6ca32ea53aaea27ba1cb001 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -146,6 +146,10 @@ CHANGES
      The internal BackRef() is gone and backref() returns a plain 
      tuple that is understood by RelationProperty.
      
+   - The version_id_col feature on mapper() will raise a warning when
+     used with dialects that don't support "rowcount" adequately.
+     [ticket:1569]
+     
    - Deprecated or removed:
       * 'allow_null_pks' flag on mapper() is deprecated.  It does
         nothing now and the setting is "on" in all cases.
index fecc16b3c74e3811d7f6f2c63f9e240add70f11d..40939d1a8d0b64ccabe7dd1e182132b7879e3aec 100644 (file)
@@ -107,7 +107,11 @@ class DefaultDialect(base.Dialect):
         #self.supports_unicode_statements = True
         #self.supports_unicode_binds = True
         #self.returns_unicode_strings = True
-
+    
+    @property
+    def dialect_description(self):
+        return self.name + "+" + self.driver
+        
     def initialize(self, connection):
         try:
             self.server_version_info = self._get_server_version_info(connection)
index 9b5583afafd928dc1777d2ef2649fd6061ed1260..881f0d5466ec1e19e8b4ddeaa8e58781dcf5cc47 100644 (file)
@@ -1414,7 +1414,7 @@ class Mapper(object):
             if update:
                 mapper = table_to_mapper[table]
                 clause = sql.and_()
-
+                
                 for col in mapper._pks_by_table[table]:
                     clause.clauses.append(col == sql.bindparam(col._label, type_=col.type))
 
@@ -1429,9 +1429,16 @@ class Mapper(object):
 
                     rows += c.rowcount
 
-                if c.supports_sane_rowcount() and rows != len(update):
-                    raise exc.ConcurrentModificationError("Updated rowcount %d does not match number of objects updated %d" % (rows, len(update)))
-
+                if connection.dialect.supports_sane_rowcount:
+                    if rows != len(update):
+                        raise exc.ConcurrentModificationError(
+                                "Updated rowcount %d does not match number of objects updated %d" %
+                                (rows, len(update)))
+                        
+                elif mapper.version_id_col is not None:
+                    util.warn("Dialect %s does not support updated rowcount "
+                            "- versioning cannot be verified." % c.dialect.dialect_description)
+                    
             if insert:
                 statement = table.insert()
                 for state, params, mapper, connection, value_params in insert:
index 37575ff3e335b229786ab5db423c881de949f7be..6b628d8264ad964f4f072eb299891c78f3b03258 100644 (file)
@@ -67,10 +67,12 @@ class VersioningTest(_base.MappedTest):
         class Foo(_base.ComparableEntity):
             pass
 
+    @testing.emits_warning(r'.*does not support updated rowcount')
     @engines.close_open_connections
     @testing.resolve_artifact_names
     def test_basic(self):
-        mapper(Foo, version_table, version_id_col=version_table.c.version_id)
+        mapper(Foo, version_table, 
+                version_id_col=version_table.c.version_id)
 
         s1 = create_session(autocommit=False)
         f1 = Foo(value='f1')
@@ -111,6 +113,27 @@ class VersioningTest(_base.MappedTest):
         else:
             s1.commit()
 
+    @engines.close_open_connections
+    @testing.resolve_artifact_names
+    def test_notsane_warning(self):
+        save = testing.db.dialect.supports_sane_rowcount
+        testing.db.dialect.supports_sane_rowcount = False
+        try:
+            mapper(Foo, version_table, 
+                    version_id_col=version_table.c.version_id)
+
+            s1 = create_session(autocommit=False)
+            f1 = Foo(value='f1')
+            f2 = Foo(value='f2')
+            s1.add_all((f1, f2))
+            s1.commit()
+
+            f1.value='f1rev2'
+            assert_raises(sa.exc.SAWarning, s1.commit)
+        finally:
+            testing.db.dialect.supports_sane_rowcount = save
+
+    @testing.emits_warning(r'.*does not support updated rowcount')
     @engines.close_open_connections
     @testing.resolve_artifact_names
     def test_versioncheck(self):
@@ -140,6 +163,7 @@ class VersioningTest(_base.MappedTest):
         s1.close()
         s1.query(Foo).with_lockmode('read').get(f1s1.id)
 
+    @testing.emits_warning(r'.*does not support updated rowcount')
     @engines.close_open_connections
     @testing.resolve_artifact_names
     def test_noversioncheck(self):