--- /dev/null
+.. change::
+ :tags: sql, bug
+ :tickets: 6135
+ :versions: 1.4.6
+
+ 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.
),
)
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:
from sqlalchemy.testing import ComparesTables
from sqlalchemy.testing import emits_warning
from sqlalchemy.testing import eq_
+from sqlalchemy.testing import expect_raises_message
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
from sqlalchemy.testing import is_false
t3.append_constraint(pk)
is_(pk._autoincrement_column, t3.c.a)
+ def test_no_kw_args(self):
+ with expect_raises_message(
+ TypeError,
+ r"Table\(\) takes at least two positional-only arguments",
+ check_context=False,
+ ):
+ Table(name="foo", metadata=MetaData())
+ with expect_raises_message(
+ TypeError,
+ r"Table\(\) takes at least two positional-only arguments",
+ check_context=False,
+ ):
+ Table("foo", metadata=MetaData())
+
class SchemaTypeTest(fixtures.TestBase):
__backend__ = True