Attribute error on '_returning' when compiling Executable ClauseElement

23 views
Skip to first unread message

Charles Langlois

unread,
May 28, 2018, 11:51:26 AM5/28/18
to sqlalchemy
Following the recipe to create an 'explain' clause element on the bitbucket repository, 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?

Mike Bayer

unread,
May 28, 2018, 12:09:11 PM5/28/18
to sqlal...@googlegroups.com
I would assume you're putting an insert(), update() , or delete() into
the explain() ? that codepath wouldn't be called otherwise, or if
you can show me exactly how to reproduce we can update the recipe.
thanks!
> --
> 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 sqlalchemy+...@googlegroups.com.
> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

Charles Langlois

unread,
May 28, 2018, 3:02:04 PM5/28/18
to sqlal...@googlegroups.com
Yes, that is the case, sorry for the lack of context.

Example:

query = delete(MyMapper.__table__).where(MyMapper.my_column == value)
result = session.execute(explain(query)) # exception occurs


You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/XtY8K3O_d68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
Charles Langlois
     Programmeur-analyste - Programmer Analyst

Montréal, QC, Canada - H2T 2A4

Mike Bayer

unread,
May 28, 2018, 3:13:47 PM5/28/18
to sqlal...@googlegroups.com


> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

--
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 a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/XtY8K3O_d68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+unsubscribe@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
Charles Langlois
     Programmeur-analyste - Programmer Analyst

--
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 sqlalchemy+unsubscribe@googlegroups.com.

Charles Langlois

unread,
May 28, 2018, 3:16:11 PM5/28/18
to sqlal...@googlegroups.com
Ok, thanks! For now, I guess setting self._returning is a reasonable workaround?


> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

--
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 a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/XtY8K3O_d68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
Charles Langlois
     Programmeur-analyste - Programmer Analyst

--
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 sqlalchemy+...@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
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 a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/XtY8K3O_d68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Mike Bayer

unread,
May 28, 2018, 3:28:19 PM5/28/18
to sqlal...@googlegroups.com
yup, as long as the recipe is doing what you need it's all good.   not sure if that prevents the RETURNING phrase from emitting, though, that's part of what i want to look into.   might change the query plan.


> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

--
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 a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/XtY8K3O_d68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+unsubscribe@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
Charles Langlois
     Programmeur-analyste - Programmer Analyst

--
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 sqlalchemy+unsubscribe@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
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 a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/XtY8K3O_d68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+unsubscribe@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
Charles Langlois
     Programmeur-analyste - Programmer Analyst

--
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 sqlalchemy+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages