diff options
| author | Jason Kirtland <jek@discorporate.us> | 2008-01-31 19:48:13 +0000 |
|---|---|---|
| committer | Jason Kirtland <jek@discorporate.us> | 2008-01-31 19:48:13 +0000 |
| commit | 3aed5fa544685a41c0486b39dfaeb98ac69be4af (patch) | |
| tree | 38ddcf38cea3e47d4e8384cf88ca6a95ee6cb78f /lib/sqlalchemy/schema.py | |
| parent | e1aa7573f210f76e2ddf8e45fc18007e11e5bbef (diff) | |
| download | sqlalchemy-3aed5fa544685a41c0486b39dfaeb98ac69be4af.tar.gz | |
- Friendlier exception messages for unbound, implicit execution
- Implicit binding failures now raise UnboundExecutionError
Diffstat (limited to 'lib/sqlalchemy/schema.py')
| -rw-r--r-- | lib/sqlalchemy/schema.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 0d626397f..44dcb5755 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -1336,5 +1336,21 @@ class SchemaVisitor(visitors.ClauseVisitor): def _bind_or_error(schemaitem): bind = schemaitem.bind if not bind: - raise exceptions.InvalidRequestError("This SchemaItem is not connected to any Engine or Connection.") - return bind
\ No newline at end of file + name = schemaitem.__class__.__name__ + label = getattr(schemaitem, 'fullname', + getattr(schemaitem, 'name', None)) + if label: + item = '%s %r' % (name, label) + else: + item = name + if isinstance(schemaitem, MetaData): + bindable = "the %s's .bind" % name + else: + bindable = "this %s's .metadata.bind" % name + + msg = ('The %s is not bound to an Engine or Connection. ' + 'Execution can not proceed without a database to execute ' + 'against. Either execute with an explicit connection or ' + 'assign %s to enable implicit execution.') % (item, bindable) + raise exceptions.UnboundExecutionError(msg) + return bind |
