Issue #45 new

Config class require a file name

Bertrand Lecervoisier avatarBertrand Lecervoisier 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 (3)

  1. Mike Bayer

    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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.