On Wed, Feb 21, 2018 at 6:14 AM,  <jens.troe...@gmail.com> wrote:
> Hello,
> Suppose I create a db session the normal way:
>
>>>> engine = engine_from_config({"sqlalchemy.url":"mysql+pymysql://…"})
>>>> Session = sessionmaker(bind=engine)
>>>> session = Session()
>
> I noticed that there is now an order dependency between:
>
>>>> session.bind.dialect.server_version_info  # None
>>>> session.query(Alembic.version_num).scalar()
> 'cb13f97d30c6'
>>>> session.bind.dialect.server_version_info  # Now contains a tuple
> (5, 6, 34)
>
> I can't quite make sense of this behavior, can somebody please shed some
> light on it?
>

SQLAlchemy doesn't connect to the database until it needs to. Creating
a Session by itself does not cause it to connect. This is mentioned in
the docs:

http://docs.sqlalchemy.org/en/latest/orm/session_basics.html

"""
The Session begins in an essentially stateless form. Once queries are
issued or other objects are persisted with it, it requests a
connection resource from an Engine that is associated either with the
Session itself or with the mapped Table objects being operated upon.
This connection represents an ongoing transaction, which remains in
effect until the Session is instructed to commit or roll back its
pending state.
"""

Hope that helps,

Simon

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to