non-mapped declared_attr warning gets in the way; is of questionable value

Issue #4221 resolved
Michael Bayer
repo owner created an issue

at http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/mixins.html#combining-table-mapper-arguments-from-multiple-mixins we document invoking __table_args__ from a mixin. if @declared_attr is used we get a warning:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative import declared_attr

Base = declarative_base()


class Mixin(object):
    a = Column(Integer)

    @declared_attr
    def __table_args__(cls):
        return (UniqueConstraint("a"), )


class Baz(Base, Mixin):
    __tablename__ = 'baz'

    id = Column(Integer, primary_key=True)
    d = Column(Integer)

    @declared_attr
    def __table_args__(cls):
        ret = list(Mixin.__table_args__)
        ret.append(UniqueConstraint("d"))
        return tuple(ret)
SAWarning: Unmanaged access of declarative attribute __table_args__ from non-mapped class Mixin

the thing we're guarding against here is the case in https://bitbucket.org/zzzeek/sqlalchemy/issues/3149/mixin_column-to-provide-more-context-for, which is already prevented here.

not clear what additional case we are guarding against here however we could also limit the warning only for names that aren't __table_args__, __mapper_args__, etc.

Comments (3)

  1. Michael Bayer reporter

    Don't warn for mixin-based table_args, mapper_args declared_attr

    Removed a warning that would be emitted when calling upon __table_args__, __mapper_args__ as named with a @declared_attr method, when called from a non-mapped declarative mixin. Calling these directly is documented as the approach to use when one is overidding one of these methods on a mapped class. The warning still emits for regular attribute names.

    Change-Id: Iae7ed0bd625a2c163c910aa777cef4779128580a Fixes: #4221

    → <<cset 37955a52995c>>

  2. Michael Bayer reporter

    Don't warn for mixin-based table_args, mapper_args declared_attr

    Removed a warning that would be emitted when calling upon __table_args__, __mapper_args__ as named with a @declared_attr method, when called from a non-mapped declarative mixin. Calling these directly is documented as the approach to use when one is overidding one of these methods on a mapped class. The warning still emits for regular attribute names.

    Change-Id: Iae7ed0bd625a2c163c910aa777cef4779128580a Fixes: #4221 (cherry picked from commit 37955a52995cdbb66a9d5835c20ee58fb98ddffc)

    → <<cset 08f18ecc3b8d>>

  3. Log in to comment