We have some elaborate logic in a a @hybrid_property and 
@<hybrid_property>.expression that I'm keen on setting up some testing to 
ensure that both cases return the same value.  I'm having some difficulty 
sorting out when each version is used at any given time though.

        @hybrid_property
        def testProp(self):
             ...etc...

        @testProp.expression(cls):
             ...etc...

        ...

        # This query generated from this does not include 'test_prop' in 
the select.
        orm_obj = Task.query.filter(Task.id == '30340').one()
        # It then executes through the @hybrid_property (python) code when 
you access it.
        print (orm_obj.test_prop)

        # This version runs through the @testProp.expression at query 
runtime, generating the value from the select
        tuples = Task.query.filter(Task.id == '30340').with_entities(Task.
test_prop)
        # And of course accessing the tuple here doesn't run the 
@hybrid_property code, as it's already there.
        print (tuples[0].test_prop)


I understand that one is an instance vs a class property, but during the 
query processing it's not clear to me when/why one would be used vs the 
other.  Is the 'with_entities' doing something here?  What other cases 
would the expression version be used?  I'm just looking for some help 
understanding the when/where/why of these. I'd really love to NOT write the 
expression version at all if possible (we won't need to filter on it in the 
query or anything), because in our case, it's just begging for us to 
introduce bugs via inconsistent implementations of the same intended logic.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to