SqlAlchemy makes strange implicit queries

I have a relationship in my user model

photos = relationship('UserPhoto', backref='user', lazy='joined')

      

After getting all the records with

users = query.all()

      

SA makes a request with LEFT OUTER JOIN in userPhoto table

I start to iterate over them and print all the properties And suddenly SA makes strange implicit requests for each record

INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:SELECT users.id AS users_id, ... FROM users 
WHERE users.id = %(param_1)s
INFO:sqlalchemy.engine.base.Engine:{'param_1': <integer idetifier>}
INFO:sqlalchemy.engine.base.Engine:SELECT user_photo.id... FROM user_photo 
WHERE %(param_1)s = user_photo.user_id
INFO:sqlalchemy.engine.base.Engine:{'param_1': <integer idetifier>}

      

I spent several hours to find out the reason, but I am still looking for

If I create unions like below:

query.options(joinedload_all('some field'))

      

SA makes only one choice with the connection

+3


source to share





All Articles