Possibly related topic, but from which I could not solve the problem: How to initialize global variables in TurboGears 2 with values from a table
The issue is that I'm trying to read some config parameters from the database when initializing some of the global variables in app_globals.py in Turbogears.
When attempting to access the database however, I receive an exception:
sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on mapper Mapper|Config|config_table, SQL expression or this Session
Just as the exception states this is probably due to the db not being bound yet (global parameters are set up first). From the other topic I was pointed in the direction of going to app_cfg.py and using "on_startup" to bind the database before initializing the global variables, but it's not working for me. Either I'm not doing it right or this is not the solution to the problem. For instance, I tried writing:
def on_startup():
print "Foo bar!!!"
base_config.register_hook('startup', on_startup)
But the print statement is never executed (the crash occurs before).
Does anyone have any pointers on where to go from here?
Thanks in advance.