On Thu, Jan 11, 2018 at 4:51 PM, Mischa S <mis...@jetbridge.com> wrote:
> In [6]: ClassificationTask.query.update(values={'completed': True})
> INFO     [sqlalchemy.engine.base.Engine] base.py:679 BEGIN (implicit)
> INFO     [sqlalchemy.engine.base.Engine] base.py:1140 UPDATE schwartz_task
> SET completed=%(completed)s
> INFO     [sqlalchemy.engine.base.Engine] base.py:1143 {'completed': True}
> Out[6]: 71
>
>
> In [7]: ClassificationTask.query.count()
> INFO     [sqlalchemy.engine.base.Engine] base.py:1140 SELECT count(*) AS
> count_1
> FROM (SELECT [...]
> FROM schwartz_task
> WHERE schwartz_task.task_type_id IN (%(task_type_id_1)s)) AS anon_1
> INFO     [sqlalchemy.engine.base.Engine] base.py:1143 {'task_type_id_1': 10}
> Out[7]: 14
>
> If I have a polymorphic discriminator, it's automatically added as a
> constraint when doing a SELECT query. When I do an update query, it's not
> automatically added. This is surprising and dangerous. Is this a bug?
>
>
> (semi-related thread:
> https://groups.google.com/forum/#!searchin/sqlalchemy/polymorphic_on$20join$20mischa%7Csort:date/sqlalchemy/U7RkHnM3R2U/332NjxnLAAAJ)
>

This is mentioned in the docs, in the "Additional Caveats for bulk
query updates:

http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.update

* The polymorphic identity WHERE criteria is not included for single-
or joined- table updates - this must be added manually, even for
single table inheritance.

So I guess it's not strictly a bug, and there's probably a good reason
why it's not being done. It might be simply that it's a bit
complicated to implement so it hasn't been done yet.

Simon

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to