On Sun, May 29, 2022, at 12:32 AM, gbr wrote:
> In SQLA 1.3.x, I used to follow this pattern to construct a query:
>
> ```
> def load_something(... sort=False):
> qry = select(columns=..., from_obj=...)
> if sort:
> qry = qry.order_by(desc(qry.c.created_on))
> if ...
> qry = qry...
> ```
>
> but in 1.4.0 and 1.4.37 (I guess the versions in between as well), this
> doesn't work any more.
as it shoudln't, because it's wrong :)
what you should do is this:
qry = select(*columns).select_from(<from_obj>)
if sort:
qry = qry.order_by(desc(qry.selected_columns.created_on))
see
https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#a-select-statement-is-no-longer-implicitly-considered-to-be-a-from-clause
for background on why using "qry.c" was always wrong and how 1.4 / 2.0 are
being changed to prevent this incorrect usage.
>
> The error message that I now get relates to aliases being created which don't
> actually exist:
>
> sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) missing
> FROM-clause entry for table "anon_2"
> LINE 4: WHERE task.type = 'xyz' ORDER BY anon_2.created_on DESC, ...
>
> I've been using this pattern quite a lot. Is there a way to reinstate this
> functionality or monkey patch my version until I changed the code?
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/f97ab789-dc20-4ebb-b639-a7019d206a84n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/f97ab789-dc20-4ebb-b639-a7019d206a84n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/899011d3-5378-4e33-a1d6-f00d2619777a%40www.fastmail.com.