raise better error when non-executable passed to execute()

Issue #3786 resolved
Philip Martin created an issue

I don't think I had this issue previously, but I have noticed since using:

python: 3.5.2 sqlalchemy: 1.0.13

I run into the error doing the following:

table = sa.Table('foobar', sa.MetaData(), sa.Column('foo', sa.CHAR(7), primary_key=True)
engine.execute(table)

Traceback (most recent call last):
    engine.execute(table)
  File "/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1991, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 914, in execute
    return meth(self, multiparams, params)
  File "/anaconda/lib/python3.5/site-packages/sqlalchemy/sql/schema.py", line 65, in _execute_on_connection
    return connection._execute_default(self, multiparams, params)
  File "/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 942, in _execute_default
    ret = ctx._exec_default(default, None)
  File "/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 952, in _exec_default
    if default.is_sequence:
AttributeError: 'Table' object has no attribute 'is_sequence'
In[80]: table.create(engine)

The ddl statement does execute when I run:

engine.create(table)

Comments (5)

  1. Mike Bayer repo owner

    engine.execute(table) is not a valid API call. the error handling seems to be thrown off a little bit, that's all.

  2. Philip Martin reporter

    Awesome, thanks. Thought it could be invalid. Appreciate the more director exception.

  3. Mike Bayer repo owner

    Check for supports_execution at ClauseElement base

    Raise a more descriptive exception / message when ClauseElement or non-SQLAlchemy objects that are not "executable" are erroneously passed to .execute(); a new exception ObjectNotExecutableError is raised consistently in all cases.

    Change-Id: I2dd393121e2c7e5b6b9e40286a2f25670876e8e4 Fixes: #3786

    → <<cset c7b9c84312b6>>

  4. Log in to comment