I'm trying to use a hybrid_property decorator to define a getter/setter. Here's the code.
class Users(object):
def __init__(self, username, uid=None, password=None, group_uid=None):
self.uid = uid
self.username = username
self.password = password
self.group_uid = group_uid
def __repr__(self):
return "User(%(username)s)" % self.__dict__
@hybrid_property
def password(self):
return self._password
@password.setter
def set_password(self, password):
self._password = password
When looking at a user object, the getter works properly, ie user.password returns a string, but calling the setter yields the following
user.test('test')
Traceback (most recent call last):
File "--removed--", line 35, in exec_expr
exec code in self.namespace, self.globs
File "<web>", line 1, in <module>
TypeError: 'str' object is not callable
Any help pointing out what I'm missing would be greatly appreciated.
PS. Using SQLAlchemy version 0.9.1
The original model was using the Classic Mapping style. Refactoring the model to use the Declarative Mapping style fixed the problem. I guess hybrid properties only work when the class is using the Declarative base.