Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation for autogen_context['imports'] now obsolete #332

sqlalchemy-bot opened this issue Oct 14, 2015 · 2 comments

documentation for autogen_context['imports'] now obsolete #332

sqlalchemy-bot opened this issue Oct 14, 2015 · 2 comments


Copy link

Migrated issue, originally created by Michael Bayer (@zzzeek)

review and test

diff --git a/alembic/autogenerate/ b/alembic/autogenerate/
index 0bdaa97..c734d2e 100644
--- a/alembic/autogenerate/
+++ b/alembic/autogenerate/
@@ -271,7 +271,7 @@ class AutogenContext(object):
             self.connection = self.migration_context.bind
             self.dialect = self.migration_context.dialect
-        self._imports = set()
+        self.imports = set()
         self.opts = opts
         self._has_batch = False
@@ -329,9 +329,10 @@ class RevisionContext(object):
         if getattr(migration_script, '_needs_render', False):
             autogen_context = self._last_autogen_context
-            autogen_context._imports = set()
+            # TODO: isn't this already on the autogen_context?
+            autogen_context.imports = set()
             if migration_script.imports:
-                autogen_context._imports.union_update(migration_script.imports)
+                autogen_context.imports.union_update(migration_script.imports)
                 autogen_context, migration_script, template_args
diff --git a/alembic/autogenerate/ b/alembic/autogenerate/
index e7a616e..9a64641 100644
--- a/alembic/autogenerate/
+++ b/alembic/autogenerate/
@@ -31,7 +31,7 @@ def _indent(text):
 def _render_python_into_templatevars(
         autogen_context, migration_script, template_args):
-    imports = autogen_context._imports
+    imports = autogen_context.imports
     for upgrade_ops, downgrade_ops in zip(
@@ -567,7 +567,7 @@ def _repr_type(type_, autogen_context):
         return rendered
     mod = type(type_).__module__
-    imports = autogen_context._imports
+    imports = autogen_context.imports
     if mod.startswith("sqlalchemy.dialects"):
         dname = re.match(r"sqlalchemy\.dialects\.(\w+)", mod).group(1)
         if imports is not None:
diff --git a/docs/build/autogenerate.rst b/docs/build/autogenerate.rst
index 549aeec..c108794 100644
--- a/docs/build/autogenerate.rst
+++ b/docs/build/autogenerate.rst
@@ -327,7 +327,7 @@ In the above example, we'd ensure our ``MySpecialType`` includes an appropriate
 The callable we use for :paramref:`.EnvironmentContext.configure.render_item`
 can also add imports to our migration script.  The ``autogen_context`` passed in
-contains an entry called ``autogen_context['imports']``, which is a Python
+contains an entry called ``autogen_context.imports``, which is a Python
 ``set()`` for which we can add new imports.  For example, if ``MySpecialType``
 were in a module called ``mymodel.types``, we can add the import for it
 as we encounter the type::

Copy link

Michael Bayer (@zzzeek) wrote:

  • Fixed an 0.8 regression whereby the "imports" dictionary member of
    the autogen context was removed; this collection is documented in the
    "render custom type" documentation as a place to add new imports.
    The member is now known as
    :attr:.AutogenContext.imports and the documentation is repaired.
    fixes documentation for autogen_context['imports'] now obsolete #332


Copy link

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants