diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-12 12:34:01 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-12 12:34:01 -0500 |
commit | 88ca587eae19afb8e069d896b95580aaed8b0e24 (patch) | |
tree | 43b8cdb72e33b201655caecac5b3467609c84dec | |
parent | dd93c6a116ff62040a938d5e63a2f71d6a2f3805 (diff) | |
download | sqlalchemy-88ca587eae19afb8e069d896b95580aaed8b0e24.tar.gz |
Count columns using PrimaryKeyConstraint.__len__ directly
PrimaryKeyConstraint is present on Table however
on table() and others it's a ColumnSet. The warning
here only needs len() and PrimaryKeyConstraint supports that
directly in the same way as ColumnSet.
Change-Id: I19c11a39110bfef48cdea49a471e7ab80b537538
Fixes: #3842
-rw-r--r-- | doc/build/changelog/changelog_11.rst | 8 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/crud.py | 2 | ||||
-rw-r--r-- | test/sql/test_insert.py | 17 |
3 files changed, 26 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 7c2e0a8fa..1a30e2a4a 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,14 @@ .. changelog:: :version: 1.1.4 + .. change:: 3842 + :tags: bug, sql + :tickets: 3842 + + Fixed bug where newly added warning for primary key on insert w/o + autoincrement setting (see :ref:`change_3216`) would fail to emit + correctly when invoked upon a lower-case :func:`.table` construct. + .. change:: default_schema :tags: bug, engine diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py index 452fe5d9a..9d10fbefc 100644 --- a/lib/sqlalchemy/sql/crud.py +++ b/lib/sqlalchemy/sql/crud.py @@ -681,7 +681,7 @@ def _warn_pk_with_no_anticipated_value(c): "Primary key columns typically may not store NULL." % (c.table.fullname, c.name, c.table.fullname)) - if len(c.table.primary_key.columns) > 1: + if len(c.table.primary_key) > 1: msg += ( " Note that as of SQLAlchemy 1.1, 'autoincrement=True' must be " "indicated explicitly for composite (e.g. multicolumn) primary " diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py index 79de40e9c..2fa1860de 100644 --- a/test/sql/test_insert.py +++ b/test/sql/test_insert.py @@ -598,6 +598,23 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): dialect=d ) + def test_anticipate_no_pk_lower_case_table(self): + t = table( + 't', + Column( + 'id', Integer, primary_key=True, autoincrement=False), + Column('notpk', String(10), nullable=True) + ) + with expect_warnings( + "Column 't.id' is marked as a member.*" + "may not store NULL.$" + ): + self.assert_compile( + t.insert(), + "INSERT INTO t () VALUES ()", + params={} + ) + class InsertImplicitReturningTest( _InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): |