]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix dependency_for final argument
authorJoe Urciuoli <joseph.w.urciuoli@gmail.com>
Wed, 19 Sep 2018 17:40:23 +0000 (13:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 1 Oct 2018 20:57:51 +0000 (16:57 -0400)
Fixed issue where part of the utility language helper internals was passing
the wrong kind of argument to the Python ``__import__`` builtin as the list
of modules to be imported.  The issue produced no symptoms within the core
library but could cause issues with external applications that redefine the
``__import__`` builtin or otherwise instrument it. Pull request courtesy Joe
Urciuoli.

Per the submitter: "The fourth argument provided to `__import__`  (which
`import_` feeds in to) is supposed to be a a list of strings, but this code is
passing a single string. This was causing the sqlalchemy `import_` function to
break the string (for example 'interfaces') into an array of single characters
['i', 'n', ...], which causes the actual `__import__` to not find the module
`sqlalchemy.orm.i` (since it's trying to import `sqlalchemy.orm.i` and
`sqlalchemy.orm.n` .. etc)"

No issue could be reproduced locally as it seems you can put anything non-
empty/None into that last argument, even a list like ``['X']``, and  all the
sub-modules seem to appear.  Omit it, and then the sub-modules aren't present.
Perhaps it just runs the module or not if this attribute is present.

Change-Id: Ia15c74620f24d24f0df4882f9b36a04e2c3725b8
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/473

doc/build/changelog/unreleased_12/pr473.rst [new file with mode: 0644]
lib/sqlalchemy/util/langhelpers.py

diff --git a/doc/build/changelog/unreleased_12/pr473.rst b/doc/build/changelog/unreleased_12/pr473.rst
new file mode 100644 (file)
index 0000000..6ee5516
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+   :tags: bug, misc
+
+   Fixed issue where part of the utility language helper internals was passing
+   the wrong kind of argument to the Python ``__import__`` builtin as the list
+   of modules to be imported.  The issue produced no symptoms within the core
+   library but could cause issues with external applications that redefine the
+   ``__import__`` builtin or otherwise instrument it. Pull request courtesy Joe
+   Urciuoli.
index 81bfee30acb3893de0af3c62f2d600a16ec88227..c2ebf7637cd581fe8a60114c7c490e3dcd0ae7a0 100644 (file)
@@ -859,7 +859,7 @@ def dependency_for(modulename):
         # unfortunately importlib doesn't work that great either
         tokens = modulename.split(".")
         mod = compat.import_(
-            ".".join(tokens[0:-1]), globals(), locals(), tokens[-1])
+            ".".join(tokens[0:-1]), globals(), locals(), [tokens[-1]])
         mod = getattr(mod, tokens[-1])
         setattr(mod, obj.__name__, obj)
         return obj