well hybrids don't apply to a load_only operation because they are not included in the query that emits when the ORM SELECTs for an object. that is, @hybrid_property.expression gives you a SQL expression, but that's never included when you say session.query(Task). It's only if you said, session.query(Task).filter(Task.hybrid_test == 'x').
There's a construct called column_property() that *is* included in the columns when you say query(Task). This is actually the kind of property that's used for all the regular columns but it also accomodates arbitrary SQL expressions. to that extent there's some overlap between column_property and hybrids which is why they are both listed at https://docs.sqlalchemy.org/en/13/orm/mapped_sql_expr.html. let me know if that makes sense. On Mon, Jun 3, 2019, at 2:17 PM, Gmoney wrote: > I should at least clarify that I have @hybrid_test.expression in place for > that property and it works when I just do the base 'get me everything' query. > > > On Monday, June 3, 2019 at 2:13:17 PM UTC-4, Gmoney wrote: >> I'm trying to use load_only and was able to get a really basic example to >> work. My problem is that once I try to load one of my hybrid properties, it >> fails. >> >> This code works for any number of basic Column properties but fails once I >> add the hybrid property: >> >> columns = (Task.msg_id, Task.hybrid_test) >> >> q = (db.session.query(Task).options(load_only(*columns).lazyload('*'))) >> >> AttributeError: Neither 'hybrid_property' object nor 'ExprComparator' object >> associated with Task.hybrid_test has an attribute 'property' >> >> >> Just wondering if I should be able to get this to work if I keep digging or >> post a more thorough code snippet, or is it not possible using this approach? > > -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/2661a10c-4741-4e5b-a1e7-2db578c5712b%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/2661a10c-4741-4e5b-a1e7-2db578c5712b%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/7f5b1969-1958-4d06-b343-171bf5136832%40www.fastmail.com. For more options, visit https://groups.google.com/d/optout.