From: Mike Bayer Date: Sat, 12 Nov 2016 17:34:01 +0000 (-0500) Subject: Count columns using PrimaryKeyConstraint.__len__ directly X-Git-Tag: rel_1_1_4~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88ca587eae19afb8e069d896b95580aaed8b0e24;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index 7c2e0a8faa..1a30e2a4ac 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 452fe5d9ad..9d10fbefc0 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 79de40e9c9..2fa1860de6 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):