pylons.config doesn't seem to care about config... at all

30 views
Skip to first unread message

Peter Hartmann

unread,
Aug 14, 2010, 11:13:33 AM8/14/10
to pylons-discuss
Hello there,
truth is, I was not using Pylons since 0.9.7, but this piece of
documentation still seems relevant:

http://pylonshq.com/docs/en/1.0/configuration/#getting-information-from-configuration-files

So I have an auth.py file in /config which sets up, well, auth. It
takes three parameters from ini, auth.secret being the first. I call
it with config['auth.secret']. Of course, I ensured to put it in
development ini. But config dictionary doesn't read it. Here's
relevant portion of traceback:

File "S:\share\projects\sources\myproject\myproject\config\auth.py",
line 17, in auth_midd
leware
secret = config['auth.secret'],
File "c:\pylons\lib\site-packages\paste-1.7.4-py2.5.egg\paste
\registry.py", li
ne 146, in __getitem__
return self._current_obj()[key]
KeyError: 'auth.secret'

Here's what is in config dict just before the call:

{'pylons.app_globals': None,
'pylons.request_options': {'errors': 'replace',
'decode_param_names': False,
'charset': 'utf-8',
'language': 'en-us'},
'pylons.paths': {'controllers': None,
'templates': [],
'static_files': None,
'root': None},
'pylons.environ_config': {'session': 'beaker.session',
'cache': 'beaker.cache'},
'pylons.strict_tmpl_context': True,
'pylons.h': None,
'pylons.package': None, '
debug': False,
'pylons.response_options': {'headers': {'Pragma': 'no-cache',
'Cache-
Control': 'no-cache'},
'errors': 'strict',
'charset': 'utf-8',
'content_type': 'text/html'},
'pylons.tmpl_context_attach_args': False}

karik...@gmail.com

unread,
Aug 19, 2010, 12:25:19 AM8/19/10
to pylons-discuss
Hi Peter,

You need to add this line at the end of
config/environment.py load_environment

pylons.config.update(config)

I still don't know whether this is issue with documentation or issue
with pylons..


On Aug 14, 8:13 pm, Peter Hartmann <mailbox....@gmail.com> wrote:
> Hello there,
> truth is, I was not using Pylons since 0.9.7, but this piece of
> documentation still seems relevant:
>
> http://pylonshq.com/docs/en/1.0/configuration/#getting-information-fr...

Wyatt Baldwin

unread,
Aug 19, 2010, 10:36:48 AM8/19/10
to pylons-discuss


On Aug 14, 8:13 am, Peter Hartmann <mailbox....@gmail.com> wrote:
> Hello there,
> truth is, I was not using Pylons since 0.9.7, but this piece of
> documentation still seems relevant:
>
> http://pylonshq.com/docs/en/1.0/configuration/#getting-information-fr...
>
> So I have an auth.py file in /config which sets up, well, auth. It
> takes three parameters from ini, auth.secret being the first. I call
> it with config['auth.secret']. Of course, I ensured to put it in
> development ini. But config dictionary doesn't read it. Here's
> relevant portion of traceback:
>
>   File "S:\share\projects\sources\myproject\myproject\config\auth.py",
> line 17, in auth_midd
> leware
>     secret = config['auth.secret'],
>   File "c:\pylons\lib\site-packages\paste-1.7.4-py2.5.egg\paste
> \registry.py", li
> ne 146, in __getitem__
>     return self._current_obj()[key]
> KeyError: 'auth.secret'


When is auth_middleware being called?

If I were you, I'd pass the `config` object that's returned from
`load_environment` to the `auth_middleware` function instead of using
`pylons.config`. Also, instead of passing the whole `config` object, I
might jst pass just the values from `config` that are needed into
`auth_middleware`.


> Here's what is in config dict just before the call:
>
> {'pylons.app_globals': None,
> 'pylons.request_options': {'errors': 'replace',
>                                      'decode_param_names': False,
>                                       'charset': 'utf-8',
>                                       'language': 'en-us'},
>  'pylons.paths': {'controllers': None,
>                         'templates': [],
>                         'static_files': None,
>                         'root': None},
> 'pylons.environ_config': {'session': 'beaker.session',
>                                    'cache': 'beaker.cache'},
>  'pylons.strict_tmpl_context': True,
> 'pylons.h': None,
> 'pylons.package': None, '
> debug': False,
> 'pylons.response_options': {'headers': {'Pragma': 'no-cache',
>                                                         'Cache-
> Control': 'no-cache'},
>                                         'errors': 'strict',
>                                        'charset': 'utf-8',
>                                        'content_type': 'text/html'},
>  'pylons.tmpl_context_attach_args': False}

At the point where you're trying to use `pylons.config`, you're using
a sort of dummy version that hasn't been fully initialized. If you
call `auth_middleware` after `load_environment` runs and pass the
`config` returned from `load_environment` to `auth_middleware`, that
should fix your problem.

In general, I'd say that `pylons.config` should only be used in a
request context.

Peter Hartmann

unread,
Aug 20, 2010, 7:41:01 AM8/20/10
to pylons-discuss


On 19 Sie, 16:36, Wyatt Baldwin <wyatt.lee.bald...@gmail.com> wrote:
>
> If I were you, I'd pass the `config` object that's returned from
> `load_environment` to the `auth_middleware` function instead of using
> `pylons.config`. Also, instead of passing the whole `config` object, I
> might jst pass just the values from `config` that are needed into
> `auth_middleware`.

That worked, thanks! I'll stick to this practice. Also:

> In general, I'd say that `pylons.config` should only be used in a
> request context.

I think docs should mention this, if they don't already.
Reply all
Reply to author
Forward
0 new messages