1. Michael Bayer
  2. alembic
  3. Issues


Issue #45 resolved

Config class require a file name

miniwark NA
created an issue

In config.py the docstrings say than the .Config class can be construct without a file with this example : {{{ from alembic.config import Config alembic_cfg = Config() alembic_cfg.set_main_option("script_location", "myapp:migrations") alembic_cfg.set_main_option("url", "postgresql://foo/bar") }}} When i try to do so and then upgrade : {{{ from alembic import command command.upgrade(alembic_cfg, 'head') }}} The upgrade command break because it require a config filename. {{{ ... File "/lib/python2.7/site-packages/alembic/command.py", line 108, in upgrade script.run_env() File "/lib/python2.7/site-packages/alembic/script.py", line 167, in run_env util.load_python_file(self.dir, 'env.py') File "/lib/python2.7/site-packages/alembic/util.py", line 176, in load_python_file module = imp.load_source(module_id, path, open(path, 'rb')) File "/testprojects/scripts/alembic/env.py", line 12, in <module> fileConfig(config.config_file_name) File "/usr/lib64/python2.7/logging/config.py", line 68, in fileConfig cp.read(fname) File "/usr/lib64/python2.7/ConfigParser.py", line 292, in read for filename in filenames: TypeError: 'NoneType' object is not iterable }}}

Alternaly the 'url' example may lead to a KeyError as it's 'sqlalchely.url' witch is need.

I was able to workaround this with this code by telling Config to use an necessary .ini file (in a pyramid project) : {{{ from alembic.config import Config from alembic import command from pyramid.paster import get_appsettings

settings = get_appsettings(developement.ini) alembic_cfg = Config('developement.ini') alembic_cfg.set_section_option('alembic', 'script_location', 'anuket:scripts/alembic') alembic_cfg.set_section_option('alembic', 'sqlalchemy.url', settings['sqlalchemy.url'])

command.upgrade(alembic_cfg, 'head') }}}

Comments (4)

  1. Michael Bayer repo owner

    this is because you have a call to logging.fileConfig in your env.py. You'd need to change that to use your application's logging system, since when you're building up the config programatically, the idea is that your alembic env is getting what it needs from the framework environment, not an .ini file directly (or if it is, you need to set that up).

    Maybe a documentation note stressing that, *you need to customize env.py*, pretty much always, to suit your environment.

  2. Log in to comment