Hi,

while upgrading one of my apps to SA 1.4, paying attention toward 2.0
compatibility, I found one single issue that I was not able to figure out
whether I'm doing something wrong or missed something in the excellent
migration guide.

All tests pass, but executing them with SQLALCHEMY_WARN_20 I noticed the
following message:

  RemovedIn20Warning: Using strings to indicate column or relationship paths
  in loader options is deprecated and will be removed in SQLAlchemy 2.0...

It was not so simple to isolate the culprit code, but I eventually found the
cause: here and there my app uses the load_only() option to load a subset of
the columns of related entities, and that's what upsets the compatibily check.

I'm attaching below a simple script that exhibits the problem (when executed
with SQLALCHEMY_WARN_20=1).

The documentation[1] shows a very similar usage, so I'm not sure where's the
problem. Maybe using joinedload(X.y).load_only(a, b), a and b cannot be column
names under 2.0, but should be Y.a and Y.b instead?

Thanks a lot for any hint,
ciao, lele.

[1] 
https://docs.sqlalchemy.org/en/14/orm/query.html#sqlalchemy.orm.Load.load_only

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/87y2a7ls26.fsf%40metapensiero.it.
from sqlalchemy import (Column, ForeignKey, Integer, MetaData, String, Text, Table,
                        create_engine, orm)


metadata = MetaData()
Base = orm.declarative_base(metadata=metadata)


class Person(Base):
    __tablename__ = 'persons'

    id = Column(Integer, primary_key=True)
    firstname = Column(String)


class Pet(Base):
    __tablename__ = 'pets'

    id = Column(Integer, primary_key=True)
    name = Column(String)
    person_id = Column(Integer, ForeignKey('persons.id'))

    person = orm.relationship(Person, backref=orm.backref('pets'))


engine = create_engine('sqlite:///:memory:', echo=True)
session = orm.sessionmaker(bind=engine)()

metadata.create_all(engine)
me = Person(firstname='Lele')
session.add(me)

yaku = Pet(name='Yaku')
session.add(yaku)

me.pets.append(yaku)

session.commit()


query = (session.query(Pet)
         .options(orm.joinedload(Pet.person)
                  .load_only('firstname')))

for pet in query:
    print(pet.name, pet.person.firstname)
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  |                 -- Fortunato Depero, 1929.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/87y2a7ls26.fsf%40metapensiero.it.

Reply via email to