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

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

Comments

Projects
None yet
2 participants
@sqlalchemy-bot

sqlalchemy-bot commented Oct 14, 2015

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

review and test

diff --git a/alembic/autogenerate/api.py b/alembic/autogenerate/api.py
index 0bdaa97..c734d2e 100644
--- a/alembic/autogenerate/api.py
+++ b/alembic/autogenerate/api.py
@@ -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)
             render._render_python_into_templatevars(
                 autogen_context, migration_script, template_args
             )
diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py
index e7a616e..9a64641 100644
--- a/alembic/autogenerate/render.py
+++ b/alembic/autogenerate/render.py
@@ -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(
             migration_script.upgrade_ops_list,
@@ -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::

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 16, 2015

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 #332

cd0bdca

@sqlalchemy-bot

This comment has been minimized.

sqlalchemy-bot commented Oct 16, 2015

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