]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added a "str()" step to the dialect_kwargs iteration for
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Jul 2014 22:09:54 +0000 (18:09 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Jul 2014 22:09:54 +0000 (18:09 -0400)
Python version < 2.6.5, working around the
"no unicode keyword arg" bug as these args are passed along as
keyword args within some reflection processes.
fixes #3123

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/util/__init__.py
lib/sqlalchemy/util/compat.py
test/sql/test_metadata.py

index 6473da10bde7ddf642f42cca6d704fe346003e24..8f6c7edc765786842b6e3b8c952544f27cc03a27 100644 (file)
     :version: 0.9.7
     :released:
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 3123
+        :versions: 1.0.0
+
+        Added a "str()" step to the dialect_kwargs iteration for
+        Python version < 2.6.5, working around the
+        "no unicode keyword arg" bug as these args are passed along as
+        keyword args within some reflection processes.
+
     .. change::
         :tags: bug, sql
         :tickets: 3122
index f9a3db285afe52e846872979bf3db0cc540bc548..1e02b3fb03b06bad53d53157ca3fb16ee0a5a176 100644 (file)
@@ -90,7 +90,7 @@ class _DialectArgView(collections.MutableMapping):
 
     def __iter__(self):
         return (
-            "%s_%s" % (dialect_name, value_name)
+            util.safe_kwarg("%s_%s" % (dialect_name, value_name))
             for dialect_name in self.obj.dialect_options
             for value_name in self.obj.dialect_options[dialect_name]._non_defaults
         )
index a2e755c3833fd62aa7b458c7ea4bb5c9378c4329..a8b823208fc3838db49d35b241959ebfafd3e966 100644 (file)
@@ -8,7 +8,8 @@
 from .compat import callable, cmp, reduce,  \
     threading, py3k, py33, py2k, jython, pypy, cpython, win32, \
     pickle, dottedgetter, parse_qsl, namedtuple, next, reraise, \
-    raise_from_cause, text_type, string_types, int_types, binary_type, \
+    raise_from_cause, text_type, safe_kwarg, string_types, int_types, \
+    binary_type, \
     quote_plus, with_metaclass, print_, itertools_filterfalse, u, ue, b,\
     unquote_plus, unquote, b64decode, b64encode, byte_buffer, itertools_filter,\
     iterbytes, StringIO, inspect_getargspec, zip_longest
index 40f7b292280477605728e462369bf398dc84cd24..35dca92ff08e188efceee2e525a9c1543b10d631 100644 (file)
@@ -18,6 +18,7 @@ py33 = sys.version_info >= (3, 3)
 py32 = sys.version_info >= (3, 2)
 py3k = sys.version_info >= (3, 0)
 py2k = sys.version_info < (3, 0)
+py265 = sys.version_info >= (2, 6, 5)
 jython = sys.platform.startswith('java')
 pypy = hasattr(sys, 'pypy_version_info')
 win32 = sys.platform.startswith('win')
@@ -34,6 +35,12 @@ else:
     except ImportError:
         import pickle
 
+# work around http://bugs.python.org/issue2646
+if py265:
+    safe_kwarg = lambda arg: arg
+else:
+    safe_kwarg = str
+
 ArgSpec = collections.namedtuple("ArgSpec",
                 ["args", "varargs", "keywords", "defaults"])
 
index 7711db816e38c87f2caed94020fb5833c6a65b41..9542711cb2b4f3fa2f93c2809e01d54f4e42af7e 100644 (file)
@@ -2517,6 +2517,19 @@ class DialectKWArgTest(fixtures.TestBase):
                 'otherunknown_foo': 'bar'}
             )  # still populates
 
+    def test_runs_safekwarg(self):
+
+        with mock.patch("sqlalchemy.util.safe_kwarg",
+            lambda arg: "goofy_%s" % arg):
+            with self._fixture():
+                idx = Index('a', 'b')
+                idx.kwargs[u'participating_x'] = 7
+
+                eq_(
+                    list(idx.dialect_kwargs),
+                    ['goofy_participating_x']
+                )
+
     def test_combined(self):
         with self._fixture():
             idx = Index('a', 'b', 'c', participating_x=7,