diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-11-26 00:59:01 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-11-26 01:12:59 -0500 |
| commit | 9e53163dbdee113f9c84311ca5804a16ac82fbf7 (patch) | |
| tree | 04c6b4729c737781908a654f0a17f9e8c1fcfb89 /test | |
| parent | 5b7665137e06485991ec4f7b7011f18d6f6b4b5e (diff) | |
| download | sqlalchemy-9e53163dbdee113f9c84311ca5804a16ac82fbf7.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
(cherry picked from commit 6ec40eca1a03a9156ee82f3ce75850778220b39e)
Diffstat (limited to 'test')
| -rw-r--r-- | test/ext/declarative/test_basic.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 5d1655e87..3eb0743e7 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -1,6 +1,7 @@ from sqlalchemy.testing import eq_, assert_raises, \ assert_raises_message, expect_warnings, is_ +from sqlalchemy.testing import assertions from sqlalchemy.ext import declarative as decl from sqlalchemy import exc import sqlalchemy as sa @@ -174,6 +175,62 @@ class DeclarativeTest(DeclarativeTestBase): assert class_mapper(Bar).get_property('some_data').columns[0] \ is t.c.data + def test_lower_case_c_column_warning(self): + with assertions.expect_warnings( + r"Attribute 'x' on class <class .*Foo.* appears to be a " + r"non-schema 'sqlalchemy.sql.column\(\)' object; ", + ): + class Foo(Base): + __tablename__ = 'foo' + + id = Column(Integer, primary_key=True) + x = sa.sql.expression.column(Integer) + y = Column(Integer) + + class MyMixin(object): + x = sa.sql.expression.column(Integer) + y = Column(Integer) + + with assertions.expect_warnings( + r"Attribute 'x' on class <class .*MyMixin.* appears to be a " + r"non-schema 'sqlalchemy.sql.column\(\)' object; ", + ): + class Foo2(MyMixin, Base): + __tablename__ = 'foo2' + + id = Column(Integer, primary_key=True) + + with assertions.expect_warnings( + r"Attribute 'x' on class <class .*Foo3.* appears to be a " + r"non-schema 'sqlalchemy.sql.column\(\)' object; ", + ): + class Foo3(Base): + __tablename__ = 'foo3' + + id = Column(Integer, primary_key=True) + + @declared_attr + def x(cls): + return sa.sql.expression.column(Integer) + + y = Column(Integer) + + with assertions.expect_warnings( + r"Attribute 'x' on class <class .*Foo4.* appears to be a " + r"non-schema 'sqlalchemy.sql.column\(\)' object; ", + ): + class MyMixin2(object): + @declared_attr + def x(cls): + return sa.sql.expression.column(Integer) + + y = Column(Integer) + + class Foo4(MyMixin2, Base): + __tablename__ = 'foo4' + + id = Column(Integer, primary_key=True) + def test_column_named_twice(self): def go(): class Foo(Base): |
