Re: [Sqlalchemy-tickets] [sqlalchemy] #2872: AliasedClass.__getattr__() creates malformed Queryable
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-11-23 13:47:32
|
#2872: AliasedClass.__getattr__() creates malformed QueryableAttribute
---------------------------+-------------------------------
Reporter: elic | Owner: zzzeek
Type: defect | Status: new
Priority: high | Milestone: 0.9.0
Component: orm | Severity: major - 1-3 hours
Resolution: | Keywords:
Progress State: in queue |
---------------------------+-------------------------------
Comment (by elic):
> ... Not really sure about that metaclass test though, just a simple
descriptor is all we need to illustrate?
I agree, my test was kinda overwrought... that `@hybrid_property` test is
much better, and anything that passes that should work fine for my use-
case. (So much of sqlalchemy I need to study, I wasn't aware of the
hybrid decorators until now! Gonna go read docs cover to cover this
weekend).
----
''sidenote: why the odd test...''
My test was extracted from a custom declarative layer, which puts it's
custom descriptor on the same attribute as one instrumented by SQLAlchemy
(rather having the descriptor on a different attribute, as in your test).
I thought that or some other unnoticed aspect might be important, so
wanted to replicate the bug as I found it, despite the crazy :)
To explain the metaclass: it's being used to intercept the
class-`setattr()` call made by `ClassManager.instrument_attribute()`, and
store the `InstrumentedAttribute` internally. This allows the custom
descriptor to wrap the `InstrumentedAttribute` at the instance level, but
return the `InstrumentedAttribute` unchanged at the class level. (Looking
back, I should probably update my code to use
`sqlalchemy.ext.instrumentation` instead of the metaclass hack, as I
wasn't aware of that feature when I started using sqlalchemy).
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2872#comment:4>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|