in my model class, i have a synthetic property that doesn't map
directly to a table field, and it is initialized in the constructor:

class User(BaseModel):
    def __init__(self):
        self._pwd = ''

    def get_pwd(self):
        return self._pwd

    def set_pwd(self, pwd):
        self._pwd = pwd
        self.hashed_password = User.hash_pwd(pwd)

    password = property(get_pwd, set_pwd)

    @classmethod
    def hash_pwd(cls, pwd):
        salt = r'somerandomcharacters'
        return md5.new(pwd + salt).hexdigest()

so calling user.password will return the non-hashed password.  this
works fine for new instances, but when i retrieve from the database
e.g.
user = session.query(User).get_by(id=1)

accessing user.password results in:
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "C:\home\jeffe\python\tg\claimsqa\claimsqa\model.py", line 255,
in get_pwd
    return self._pwd
AttributeError: 'User' object has no attribute '_pwd'

is SA not calling __init__ or am i doing something wrong?
thanks,
jeff

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to