Skip to content

Unexecuted import-time Session.query() thwarts Session.configure(bind=x) #1924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sqlalchemy-bot opened this issue Sep 20, 2010 · 4 comments
Closed
Labels
bug Something isn't working orm
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Anonymous

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")

Attachments: test_sqlalchemy.py

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

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.

@sqlalchemy-bot
Copy link
Collaborator Author

Anonymous wrote:

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")

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

a warning is committed in 634d547

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.6.5"
  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working orm labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.6.5 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working orm
Projects
None yet
Development

No branches or pull requests

1 participant