20 Jun 2012 19:13
mixing association proxies and mixin classes
Wichert Akkerman <wichert <at> wiggy.net>
2012-06-20 17:13:34 GMT
2012-06-20 17:13:34 GMT
I am struggling a little bit with mixin classes. The pattern I am trying
to implement is a mixin-class that adds a list of validated search
queries to a model. A minimised version of the code is below. The
problem I am running into is that putting an association_proxy on a
mixin class does not appear to work here: it always picks the first seen
class type to create new values instead of picking up what the
relationship of the current instance requires. With the example below
that results in this error:
AssertionError: Attribute '_filters' on class '<class '__main__.TypeB'>' doesn't handle objects of
type'<class '__main__.FilterA'>'
My initial though was that this might be fixed by making the
association_proxy instance itself a declared_attr, but that results in
other problems.
Is there an alternative way to implement this, or is this a bug in the
declarative logic?
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative import declared_attr
metadata = MetaData()
BaseObject = declarative_base(metadata=metadata)
class BaseFilter(BaseObject):
__abstract__ = True
(Continue reading)
RSS Feed