summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-11-26 00:59:01 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-11-26 01:12:01 -0500
commit6ec40eca1a03a9156ee82f3ce75850778220b39e (patch)
treea70bd6198fdf64df2d29f7d6a715e260c94e8213 /lib/sqlalchemy
parentb5cb68ac432bb7477642305504ddcfdb3edaf87f (diff)
downloadsqlalchemy-6ec40eca1a03a9156ee82f3ce75850778220b39e.tar.gz
Warn for lower-case column attribute on declarative
A warning is emitted in the case that a :func:`.column` object is applied to a declarative class, as it seems likely this intended to be a :class:`.Column` object. Fixes: #4374 Change-Id: I2e617ef65547162e3ba6587c168548ad0cf6203d
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/ext/declarative/base.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py
index e5bc670b3..f1d75bb4b 100644
--- a/lib/sqlalchemy/ext/declarative/base.py
+++ b/lib/sqlalchemy/ext/declarative/base.py
@@ -303,6 +303,11 @@ class _MapperConfig(object):
if isinstance(ret, (Column, MapperProperty)) and \
ret.doc is None:
ret.doc = obj.__doc__
+ # here, the attribute is some other kind of property that
+ # we assume is not part of the declarative mapping.
+ # however, check for some more common mistakes
+ else:
+ self._warn_for_decl_attributes(base, name, obj)
if inherited_table_args and not tablename:
table_args = None
@@ -311,6 +316,14 @@ class _MapperConfig(object):
self.tablename = tablename
self.mapper_args_fn = mapper_args_fn
+ def _warn_for_decl_attributes(self, cls, key, c):
+ if isinstance(c, expression.ColumnClause):
+ util.warn(
+ "Attribute '%s' on class %s appears to be a non-schema "
+ "'sqlalchemy.sql.column()' "
+ "object; this won't be part of the declarative mapping" %
+ (key, cls))
+
def _produce_column_copies(self, base):
cls = self.cls
dict_ = self.dict_
@@ -382,6 +395,7 @@ class _MapperConfig(object):
# and place the evaluated value onto the class.
if not k.startswith('__'):
dict_.pop(k)
+ self._warn_for_decl_attributes(cls, k, value)
if not late_mapped:
setattr(cls, k, value)
continue