I finally found the root cause of the "MySQL session has gone away"
errors that I posted about in
http://groups.google.com/group/pylons-discuss/browse_thread/thread/c0f1fe15c841303.
I'm using repoze.what.plugins.quickstart, following the example at
http://wiki.pylonshq.com/display/pylonscookbook/Authorization+with+repoze.what:
from admin.model.meta import Session
from admin.model.backoffice import BackOfficeUser
def add_auth(app):
return setup_sql_auth(app, BackOfficeUser, None, None,
Session.
post_login_url='/logged_in', post_logout_url='/
logged_out')
Apparently meta.Session is imported here before it's assigned its
final value by admin.model.init_model, so even though add_auth is
executed after init_model, it gets the pre-init_model version of
Session, so it ends up using its own session, separate from the rest
of the app, that's never removed and never recycled.
I guess I'm confused now as to why meta.Session is set up the way it
is. This approach seems like it can introduce subtle bugs; what's the
best way to avoid bugs like this in the future?
Specific questions:
Should I update the wiki.pylonshq.com article to use meta.Session
instead of importing Session directly?
If using the pre-init_model meta.Session can introduce bugs, then why
not set it to None (so attempts to use it will fail completely)
instead of scoped_session(sessionmaker())?
In general, is "from admin.model import meta" (then write code
referring to "meta.Session") better style than "from admin.model.meta
import Session" (then write code referring to "Session")?
Using "from admin.model.meta import Session" is obviously unsafe in
the repoze.what sample app's auth.py. Are there other places where
"from admin.model.meta import Session" is always safe to use or always
unsafe to use?
Does Python offer a way to have the shorter syntax of "from
admin.model.meta import Session" (so I can write code referring to
"Session") without having to worry about "Session" being reassigned to
something else? (I guess I want a way to import "Session" as a
reference to "meta.Session" instead of importing the value of the
current "meta.Session" reference.)
--
Josh Kelley
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.