_label expected on Function objects | since SA 0.5.0

Issue #1302 resolved
Former user created an issue
# The last line (query) fails with 0.5.0 - 0.5.2 and todays Mercurial trunk.
# Works well with 0.4.8,0.4.7p1 (at least)
# Tractrace Tip with 0.5.2:
#  File "/home/rr/dev/fremd/SQLAlchemy-0.5.2/lib/sqlalchemy/sql/compiler.py", line 460, in #label_select_column
#    if select.use_labels and column._label:
#AttributeError: 'Function' object has no attribute '_label'
#
# Environment: CPython 2.5 on AMD64 Linux
# EMail: tmp2@reifenberg.de
#
# (Or did I miss an API change with 0.5, requiring me 
# to respect the new label functionality ?? Sorry in this case. )
# Ruben

from sqlalchemy import *
from sqlalchemy.orm import *


class User(object):
    def __init__(self, sicher, unsicher):
        self.sicher = sicher
    def _get_sicher(self):
        return self._func_sicher
    def _set_sicher(self, value):
        self._sicher = func.AES_ENCRYPT(value, "aeskey")
    sicher = property(_get_sicher, _set_sicher)


# the AES_ENCRYPT function is MySQL only :-|
# but to demonstrate the bug, sqlite is sufficient:
#db = create_engine("sqlite:///:memory:",assert_unicode=True,echo=True)
db = create_engine("mysql://spam@localhost/satest1",assert_unicode=True,echo=True)

session = sessionmaker(autoflush=False)()
metadata = MetaData(db)    
t_user = Table("user",metadata,
    Column("id",Integer,primary_key=True),
    Column("sicher",Text),
    )
metadata.drop_all()
metadata.create_all()
mapper(User, t_user, properties={
        '_sicher':t_user.c.sicher,
        '_func_sicher':column_property(func.AES_DECRYPT(t_user.c.sicher, "aeskey")),
        'sicher':synonym('_func_sicher'),    
        }    
    )
session.query(User).all()

Comments (2)

  1. Log in to comment