]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Count columns using PrimaryKeyConstraint.__len__ directly
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 12 Nov 2016 17:34:01 +0000 (12:34 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 12 Nov 2016 17:34:01 +0000 (12:34 -0500)
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
doc/build/changelog/changelog_11.rst
lib/sqlalchemy/sql/crud.py
test/sql/test_insert.py

index 7c2e0a8faaeeec9b9c59af89493c041d372f50e8..1a30e2a4ac0c127fc3270e953eca569fa0cf2c4c 100644 (file)
 .. 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
 
index 452fe5d9ad4b9ad4225aadf77d1c4ef8666d4bc2..9d10fbefc025563cfa5eaedb4acb64daf645c899 100644 (file)
@@ -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 "
index 79de40e9c915bb687d73f2f9cd1b4419f994a2da..2fa1860de6e9972eea94cdca94e80eeffeee12a2 100644 (file)
@@ -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):