I'm having trouble getting mixins to play nicely with __table_args__.
Using the example I gave earlier in this thread:

On Jan 13, 1:00 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> On Jan 13, 2011, at 12:11 PM, Randall Nortman wrote:
[...]
> >    namespace_id = Column(Integer, ForeignKey(Namespace.id),
> > nullable=False)
> >    namespace = relationship(Namespace, backref='widgets')
> >    name = Column(Unicode(256), nullable=False)
> >    __table_args__ = (
> >        UniqueConstraint(namespace_id, name),
> >        {})
[...]

I can stick that code in a mixin class (converting everything but
'name' to be a @declared_attr), and it works just fine -- until a
class using the mixin wants to have some __table_args__ of its own.
The docs have an example of manually combining __table_args__ from
mixins in the class that uses the mixin, but I find that a little bit
ugly.  In particular in this case, the mixin doesn't just use a dict
as its __table_args__, so the derived class needs to know that (or
test for that) and pull in the positional arguments and also the
dict.  I don't like that, because the derived class needs to know too
much about the internals of the mixin, and I may change those
internals at some point, or else it needs some complicated code to
introspect the type of the mixin's __table_args__ (which may be a
sequence, a dict, or a @declared_attr method returning a sequence or a
dict).

Is there a nice solution that doesn't require a user of the mixin to
bend over backward to add its own __table_args__ without obliterating
the mixin's __table_args__?  I would rather put complicated code in
the mixin rather than the user of the mixin, but if the user specifies
__table_args__, then the mixin's __table_args__ never seems to be
called in order to have the opportunity to do any magic.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to