From 7afcb39a962d383e5ba04179c1b13131fb08a787 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 6 Sep 2019 18:40:46 -0400 Subject: Catch set_parent_w_dispatch missing Added an explicit error message for the case when objects passed to :class:`.Table` are not :class:`.SchemaItem` objects, rather than resolving to an attribute error. Fixes: #4847 Change-Id: I4dcdcee86b64c85ccf12e2ddc3d638563d307991 --- lib/sqlalchemy/sql/schema.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/schema.py') diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index d9667e445..69fc9408f 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -104,7 +104,15 @@ class SchemaItem(SchemaEventTarget, visitors.Visitable): for item in args: if item is not None: - item._set_parent_with_dispatch(self) + try: + spwd = item._set_parent_with_dispatch + except AttributeError: + raise exc.ArgumentError( + "'SchemaItem' object, such as a 'Column' or a " + "'Constraint' expected, got %r" % item + ) + else: + spwd(self) def get_children(self, **kwargs): """used to allow SchemaVisitor access""" -- cgit v1.2.1