On Fri, Nov 11, 2016 at 1:53 PM, Michael Williamson <mich...@healx.io> wrote:
>
>> I think your code is basically fine, you've just got a mistake on the
>> last line. Presumably you meant to query Person, not Person.born?
>
>
> I want Person.born so that I don't have to get the entire object. It doesn't
> make much difference in this example, but is quite important for us in
> practice when we're grabbing multiple expressions.
>
>>
>> hybrid_property does't care about the name of the "fget" function, it
>> just calls it, passing the instance as the only parameter:
>>
>>
>> https://bitbucket.org/zzzeek/sqlalchemy/src/f2eb4aac9517a3775411c2ecf0f588ffd0d790f6/lib/sqlalchemy/ext/hybrid.py?at=master&fileviewer=file-view-default#hybrid.py-744
>>
>
> The call to util.update_wrapper sets the property to have the same name as
> the fget function, which in turn is used when creating the SQL expression
> (the self.__name__ expression in the comparator method), which determines
> the label of the value in the result object.
>

OK, I'm probably missing something. I don't have access to PG right
now, so I couldn't run your code directly. Having said that, I'm
surprised that the comparator object is even invoked in the
expression:

    session.query(Person.born).one().born == '1881'

...because "session.query(Person.born).one()" returns a tuple-ish
object with 1 element, which won't have a "born" attribute.

Anyway, to answer your original question, would it be sufficient to
update the __name__ attribute of your instance_get function inside
json_property?

ie.

def json_property(json_column, name, type_=None):
    def instance_get(self):
        return getattr(self, json_column.key)[name]
    instance_get.__name__ = name

Simon

-- 
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