]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- assorted fixes raised by pypy 2.1beta2, but all of which are good
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 2 Aug 2013 00:25:56 +0000 (20:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 2 Aug 2013 00:25:56 +0000 (20:25 -0400)
ideas in general:
  - pypy2.1 w/ sqlite3 is the first DBAPI we're seeing returning
    unicode in cursor.description without being py3k.  add a new on-connect
    check for this, if we get back a u"", just don't do description decoding,
    should be OK for now.
  - the set tests in test_collection were assuming the two sets would be ordered
    the same when it tested pop(), can't really assume that.
  - test_serializer gets worse and worse, pickle is just not really viable here,
    ding out pypy
  - pypy2.1b2 seems to allow cursor.lastrowid to work (or we changed something?)
  - pool._threadconns.current() is a weakref, it can be None
  - another one of those logging.handlers imports

lib/sqlalchemy/engine/default.py
lib/sqlalchemy/pool.py
lib/sqlalchemy/testing/suite/test_insert.py
test/orm/test_collection.py
test/orm/test_mapper.py
test/requirements.py

index 3e8e96a42c7a82b215cf0fc771ef102e46b03f57..b8c3768a8c4623605986fa2e9d9c74031aafd23d 100644 (file)
@@ -191,6 +191,10 @@ class DefaultDialect(interfaces.Dialect):
 
         self.returns_unicode_strings = self._check_unicode_returns(connection)
 
+        if self.description_encoding is not None and \
+            self._check_unicode_description(connection):
+            self._description_decoder = self.description_encoding = None
+
         self.do_rollback(connection.connection)
 
     def on_connect(self):
@@ -248,6 +252,26 @@ class DefaultDialect(interfaces.Dialect):
         else:
             return unicode_for_varchar
 
+    def _check_unicode_description(self, connection):
+        # all DBAPIs on Py2K return cursor.description as encoded,
+        # until pypy2.1beta2 with sqlite, so let's just check it -
+        # it's likely others will start doing this too in Py2k.
+
+        if util.py2k and not self.supports_unicode_statements:
+            cast_to = util.binary_type
+        else:
+            cast_to = util.text_type
+
+        cursor = connection.connection.cursor()
+        cursor.execute(
+            cast_to(
+                expression.select([
+                    expression.literal_column("'x'").label("some_label")
+                ]).compile(dialect=self)
+            )
+        )
+        return isinstance(cursor.description[0][0], util.text_type)
+
     def type_descriptor(self, typeobj):
         """Provide a database-specific :class:`.TypeEngine` object, given
         the generic object which comes from the types module.
index 498b001c15f3199bad17961f2d2610dcd8bc7693..f2d6ca6ea4350640e34f92f4c3f4953f29fc22cb 100644 (file)
@@ -277,7 +277,8 @@ class Pool(log.Identified):
         except AttributeError:
             pass
         else:
-            return rec.checkout_existing()
+            if rec is not None:
+                return rec.checkout_existing()
 
         return _ConnectionFairy.checkout(self, self._threadconns)
 
index e671eeb7a2f4516e868845e9df06eaac2d1edd2a..21141f244dc1a1f47ad70e6bf70d02bed67c7822 100644 (file)
@@ -56,8 +56,9 @@ class LastrowidTest(fixtures.TablesTest):
             [pk]
         )
 
-    @exclusions.fails_if(lambda: util.pypy, "lastrowid not maintained after "
-                            "connection close")
+    # failed on pypy1.9 but seems to be OK on pypy 2.1
+    #@exclusions.fails_if(lambda: util.pypy, "lastrowid not maintained after "
+    #                        "connection close")
     @requirements.dbapi_lastrowid
     def test_native_lastrowid_autoinc(self):
         r = config.db.execute(
index c9f9f6951db9f5d1d934cc3998e00b49e4e24460..fab2aac967fc35ac90558d1f129528f8ad2d2066 100644 (file)
@@ -499,9 +499,9 @@ class CollectionsTest(fixtures.ORMTest):
         control = set()
 
         def assert_eq():
-            self.assert_(set(direct) == canary.data)
-            self.assert_(set(adapter) == canary.data)
-            self.assert_(direct == control)
+            eq_(set(direct), canary.data)
+            eq_(set(adapter), canary.data)
+            eq_(direct, control)
 
         def addall(*values):
             for item in values:
@@ -519,10 +519,6 @@ class CollectionsTest(fixtures.ORMTest):
         addall(e)
         addall(e)
 
-        if hasattr(direct, 'pop'):
-            direct.pop()
-            control.pop()
-            assert_eq()
 
         if hasattr(direct, 'remove'):
             e = creator()
@@ -599,6 +595,12 @@ class CollectionsTest(fixtures.ORMTest):
             control.clear()
             assert_eq()
 
+        if hasattr(direct, 'pop'):
+            addall(creator())
+            direct.pop()
+            control.pop()
+            assert_eq()
+
         if hasattr(direct, 'difference_update'):
             zap()
             e = creator()
@@ -739,6 +741,7 @@ class CollectionsTest(fixtures.ORMTest):
             except TypeError:
                 assert True
 
+
     def _test_set_bulk(self, typecallable, creator=None):
         if creator is None:
             creator = self.entity_maker
index 06ec4ce272bae028c91add4b9de25e87aad8a915..e742505b0e1f3e599c63e58049af5ec6342a2667 100644 (file)
@@ -17,6 +17,7 @@ from sqlalchemy.testing import fixtures
 from test.orm import _fixtures
 from sqlalchemy.testing.assertsql import CompiledSQL
 import logging
+import logging.handlers
 
 class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL):
     __dialect__ = 'default'
index a56c037d1984449b1a904d7e45ea3707a89947e6..2bd39540482af96e0924d004c92e15e8d67fdcb5 100644 (file)
@@ -579,8 +579,9 @@ class DefaultRequirements(SuiteRequirements):
     def non_broken_pickle(self):
         from sqlalchemy.util import pickle
         return only_if(
-            lambda: pickle.__name__ == 'cPickle' or sys.version_info >= (3, 2),
-            "Needs cPickle or newer Python 3 pickle"
+            lambda: not util.pypy and pickle.__name__ == 'cPickle'
+                or sys.version_info >= (3, 2),
+            "Needs cPickle+cPython or newer Python 3 pickle"
         )