--- /dev/null
+.. change::
+ :tags: bug, declarative
+ :tickets: 4221
+
+ 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.
from ... import util
from ... import exc
import weakref
+import re
from .base import _as_declarative, \
_declarative_constructor,\
def __get__(desc, self, cls):
reg = cls.__dict__.get('_sa_declared_attr_reg', None)
if reg is None:
- manager = attributes.manager_of_class(cls)
- if manager is None:
+ if not re.match(r'^__.+__$', desc.fget.__name__) and \
+ attributes.manager_of_class(cls) is None:
util.warn(
"Unmanaged access of declarative attribute %s from "
"non-mapped class %s" %
getattr, Mixin, "my_prop"
)
+ def test_can_we_access_the_mixin_straight_special_names(self):
+ class Mixin(object):
+ @declared_attr
+ def __table_args__(cls):
+ return (1, 2, 3)
+
+ @declared_attr
+ def __arbitrary__(cls):
+ return (4, 5, 6)
+
+ eq_(Mixin.__table_args__, (1, 2, 3))
+ eq_(Mixin.__arbitrary__, (4, 5, 6))
+
def test_non_decl_access(self):
counter = mock.Mock()