#2432: call_on_startup functions do not successfully modify things in tg.config
------------------------+---------------------------------------------------
Reporter: toshio | Owner:
Type: defect | Status: new
Priority: normal | Milestone: __unclassified__
Component: TurboGears | Version: 2.0.3
Severity: normal | Keywords:
------------------------+---------------------------------------------------
I have a library that does a few things for a TG2 app. To make things
easy on the people who will be using my library in their apps I have a
function to call on application startup to set a few things up. Among
other things, this function attempts to modify
base_config.variable_providers and base_config.ignore_parameters. Here's
the code:
{{{
def enable_csrf():
# Ignore the _csrf_token parameter
ignore = config.get('ignore_parameters', [])
print 'before', config.get('ignore_parameters', [])
print 'before', config.get('variable_provider', [])
if '_csrf_token' not in ignore:
ignore.append('_csrf_token')
config.update['ignore_parameters'] = ignore
# Add a function to the template tg stdvars that looks up a template.
var_provider = config.get('variable_provider', None)
if var_provider:
config['variable_provider'] = lambda: \
var_provider().update({'fedora_template': fedora_template})
else:
config['variable_provider'] = lambda: {'fedora_template':
fedora_template}
print 'after', config.get('ignore_parameters', [])
print 'after', config.get('variable_provider', [])
config/app_cfg.py:
base_config.call_on_startup = [enable_csrf]
}}}
When used like this, call_on_startup runs the enable_csrf() function but
the modifications of tg.config['ignore_parameters'] and
tg.config['variable_providers'] do not show up outside of the
enable_csrf() function.
elpargo took an initial look at the function over IRC and had these
comments:
right. It indeed seems like a) a bug in startup or b) we need a separate
hook. take a look at tg/configuration. make_load_environment sets up the
functions at setup_startup_and_shutdown the comment stays it will Register
the functions however it is actually calling them. however in
setup_tg_wsgi_app/make_base_app which is when things are actually created
there is no call for that. to be honest I have never needed those, but
this code doesn't seems right. all those setup_* functions are supposed to
pull things in rather than execute them.
I have reworked my code to call my startup function in an overridden
AppConfig which may work out better for me in the long-run but thought
this should either be addressed as a code or documentation bug. I can
provide more code examples if needed but I'm out of town until January
4th.
--
Ticket URL: <http://trac.turbogears.org/ticket/2432>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en