Unexecuted import-time Session.query() thwarts Session.configure(bind=x)
Issue #1924
resolved
Thankfully, it's very easy to not do the below. But when it's going on it is very unclear why the error has occurred.
{{{
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
S = scoped_session(sessionmaker())
q = S.query(sqlalchemy.func.max())
def test_session():
the_engine = create_engine('sqlite://')
S.configure(bind=the_engine)
S.execute("SELECT 1")
Comments (4)
-
repo owner -
Account Deleted I'm not sure what it should do, but if I change the code to explicitly create a session,
Maybe it could be a warning? My code is a multi-threaded web application so when not in testing a new scoped_session comes into play. At the console S.execute() gives the 'no bind' error but in the normal running application S.execute("SELECT 1") works despite import-time Query brokenness. {{{ import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker S = scoped_session(sessionmaker()) q = S.query(sqlalchemy.func.max()) def test_session(): the_engine = create_engine('sqlite://') s = S(bind=the_engine) s.execute("SELECT 1")
-
repo owner a warning is committed in 634d54742523883316bd7768c8d2918e8410aa62
-
repo owner - removed milestone
Removing milestone: 0.6.5 (automated comment)
- Log in to comment
what logic would you have SQLAlchemy apply here? Most blunt would be, configure() raises an error once any session has been created. I'm not sure what other options exist besides that. I can see some users having an issue with such a behavior.