On Monday, June 18, 2018 at 5:07:53 PM UTC+2, Piotr Pawlicki wrote:
>
>
> Dear all,
>
> I'm having troubles accessing DB data from a function registered as a
> startup hook in my TG2 application.
>
> Minimalist code to illustrate:
> def on_startup():
> print DBSession.query(User).count()
>
> tg.hooks.register('startup', on_startup)
>
>
> It works like a charm in a shutdown hook, but in the startup hook an
> exception is raised: "*UnboundExecutionError: Could not locate a bind
> configured on Mapper|User|user, SQL expression or this Session.*".
>
> I understand in this case the DBSession is not ready when the startup hook
> is called, but I don't see another hook that would fit.
> I defined the hooks in *app_cfg.py*, as I understand this is the common
> practice. Should the startup hook be defined elsewhere in that case?
>
> Thank you and best regards,
>
After my previous message, I found another page when looking for
information on adding configuration options:
http://turbogears.readthedocs.io/en/latest/turbogears/configuration/appconfig.html#configuration-milestones
http://turbogears.readthedocs.io/en/latest/turbogears/configuration/appconfig.html#milestones-and-hooks-order-of-execution
Those sections allowed me to understand 'startup' hooks are called really
early and the process.
Moving my 'startup' hook to 'after_config', once the environment is fully
loaded and configuration has taken place solved my issue.
I don't know if the way I solved it is the preferred one, but to me the
description *'startup() - application wide only, called when the
application is going to start *has been misleading
(http://turbogears.readthedocs.io/en/latest/turbogears/hooks.html#available-hooks).
Best regards,
--
Piotr PAWLICKI
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.