Hi,
I've been adding a hybrid property to a model as per the documentation at
http://docs.sqlalchemy.org/en/latest/orm/extensions/hybrid.html. In
particular, the behavior is complicated enough that I need to define the
expression version of the property separate from the normal version.
My model looks like this:
class MyModel(object):
# ...
@hybrid_property
def my_property(self):
# Do some stuff at the instance level
@my_property.expression
def my_property(cls):
# Do some stuff at the class level
This works as expected, but if I change the name of the class function it
suddenly stops working - based on the error it seems like the renamed class
function is being ignored and the instance function is being used instead.
Weirdly, this does not happen when using hybrid methods rather than
properties - so the following works as expected:
class MyModel(object):
# ...
@hybrid_method
def my_property(self):
# Do some stuff at the instance level
@my_property.expression
def my_property_expression(cls):
# Do some stuff at the class level
This is confusing - from the look of the code, the two decorators seem to
work in the same way, so I am not sure why the renaming matters to the
property and not the method. Is this expected behaviour?
Thanks,
James
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.