Config class require a file name

Issue #45 resolved
miniwark NA
created an issue

In 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/", line 108, in upgrade script.run_env() File "/lib/python2.7/site-packages/alembic/", line 167, in run_env util.load_python_file(self.dir, '') File "/lib/python2.7/site-packages/alembic/", line 176, in load_python_file module = imp.load_source(module_id, path, open(path, 'rb')) File "/testprojects/scripts/alembic/", line 12, in <module> fileConfig(config.config_file_name) File "/usr/lib64/python2.7/logging/", line 68, in fileConfig File "/usr/lib64/python2.7/", 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 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*, pretty much always, to suit your environment.

  2. Log in to comment