joinedload().load_only() emits 2.0 warning

162 views
Skip to first unread message

Lele Gaifax

unread,
Jul 15, 2021, 7:45:09 AM7/15/21
to sqlal...@googlegroups.com
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

test.py

Mike Bayer

unread,
Jul 15, 2021, 8:28:29 AM7/15/21
to noreply-spamdigest via sqlalchemy
i can look later, if i forget after a day or so please post this to github discussions and/or issues where i will notice it better
-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


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+...@googlegroups.com.


-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
le...@metapensiero.it  |                 -- Fortunato Depero, 1929.

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


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+...@googlegroups.com.


Attachments:
  • test.py

Federico Caselli

unread,
Jul 16, 2021, 2:12:39 AM7/16/21
to sqlalchemy
Hi.

As the warning mebtions, the issue is that you are using the string name with load only instead of the column from the class.
In this load only from the file:

.load_only('firstname')))

Lele Gaifax

unread,
Jul 16, 2021, 3:22:52 AM7/16/21
to sqlal...@googlegroups.com
Federico Caselli <cfede...@gmail.com> writes:

> As the warning mebtions, the issue is that you are using the string name
> with load only instead of the column from the class.

Ok, so maybe we should explain the difference in the joinedload().load_only()
documentation? As said, the sample code attached to the generic load_only()
function documentation uses the string name.

ciao, lele.

Federico Caselli

unread,
Jul 16, 2021, 4:39:51 AM7/16/21
to sqlalchemy
There is no difference, it's the documentation that's outdated.

We should update that

Lele Gaifax

unread,
Jul 16, 2021, 8:00:33 AM7/16/21
to sqlal...@googlegroups.com
Federico Caselli <cfede...@gmail.com> writes:

> There is no difference, it's the documentation that's outdated.
>
> We should update that

I see, thank you for the clarification!

Federico Caselli

unread,
Jul 20, 2021, 3:00:29 AM7/20/21
to sqlalchemy

Lele Gaifax

unread,
Jul 22, 2021, 1:57:50 AM7/22/21
to sqlal...@googlegroups.com
Federico Caselli <cfede...@gmail.com> writes:

> Updated here https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2959

Great, thank you!
Reply all
Reply to author
Forward
0 new messages