From 3de954bc027ebf655e7ed26c83cfb3fd4b7b5edf Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Mon, 5 Apr 2021 21:57:24 +0200 Subject: Table arguments name and metadata are positional only The :class:`_sql.Table` object now raises an informative error message if it is instantiated without passing at least the :paramref:`_sql.Table.name` and :paramref:`_sql.Table.metadata` arguments positionally. Previously, if these were passed as keyword arguments, the object would silently fail to initialize correctly. Fixes: #6135 Change-Id: I54d0c89fd549fc504289a87ea0bb37369f982b06 --- lib/sqlalchemy/sql/schema.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 9d7617370..f2c1c86ec 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -546,14 +546,17 @@ class Table(DialectKWArgs, SchemaItem, TableClause): ), ) def __new__(cls, *args, **kw): - if not args: + if not args and not kw: # python3k pickle seems to call this return object.__new__(cls) try: name, metadata, args = args[0], args[1], args[2:] except IndexError: - raise TypeError("Table() takes at least two arguments") + raise TypeError( + "Table() takes at least two positional-only " + "arguments 'name' and 'metadata'" + ) schema = kw.get("schema", None) if schema is None: -- cgit v1.2.1