Following the recipe to create an 'explain' clause element on the bitbucket 
repository 
<https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Explain>, trying 
to execute a query using `explain` result in an attribute error:

SubTest error: Traceback (most recent call last):
  File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/lib/python3.6/unittest/case.py", line 523, in subTest
    yield
  File "/home/charles/PycharmProjects/my_project/models.py", line 39, in 
test_delete_cascade
    result = self.session.execute(explain_query).fetchall()
  File 
"/home/charles/PycharmProjects/my_project/.env/lib/python3.6/site-packages/sqlalchemy/orm/session.py"
, line 1170, in execute
    bind, close_with_result=True).execute(clause, params or {})
  File 
"/home/charles/PycharmProjects/my_project/.env/lib/python3.6/site-packages/sqlalchemy/engine/base.py"
, line 948, in execute
    return meth(self, multiparams, params)
  File 
"/home/charles/PycharmProjects/my_project/.env/lib/python3.6/site-packages/sqlalchemy/sql/elements.py"
, line 269, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File 
"/home/charles/PycharmProjects/my_project/.env/lib/python3.6/site-packages/sqlalchemy/engine/base.py"
, line 1053, in _execute_clauseelement
    if not self.schema_for_object.is_default else None)
  File "<string>", line 1, in <lambda>
  File 
"/home/charles/PycharmProjects/my_project/.env/lib/python3.6/site-packages/sqlalchemy/sql/elements.py"
, line 442, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File 
"/home/charles/PycharmProjects/my_project/.env/lib/python3.6/site-packages/sqlalchemy/sql/elements.py"
, line 448, in _compiler
    return dialect.statement_compiler(dialect, self, **kw)
  File 
"/home/charles/PycharmProjects/my_project/.env/lib/python3.6/site-packages/sqlalchemy/sql/compiler.py"
, line 457, in __init__
    ) and statement._returning:
AttributeError: 'explain' object has no attribute '_returning'

Adding 'self._returning = False' in the __init__ of explain solves the 
issue. Maybe something is missing in the documentation?

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to