Incorrect multi-table DELETE..USING
SQL query when deleting Joined Inheritance Relationship object declared using __mapper_args__ = {'with_polymorphic': '*'}
with SQAlchemy 1.4
#6178
Replies: 1 comment 5 replies
-
hey there - MySQL's DELETE..USING syntax is fairly specific to MySQL, while Postrgresql I think might also supports some variant of this, these structures are not generally available in SQL on most other databases, and the ORM generally can't support such consttructs. For this reason, ORM-enabled UPDATE and DELETE of multiple rows are explicitly not supported for joined-table inheritance setups, and this is documented in the big pink dragon box at https://docs.sqlalchemy.org/en/14/orm/session_basics.html#orm-expression-update-delete :
in short, none of this is tested or supported and it's out of scope; if you need mass UPDATE/DELETE of these structures, invoke your SQL using session.connection().execute() so that no ORM functionalities are used. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Query.delete()
generates incorrect multi-tableDELETE..USING
SQL query when deleting parent object declared by mapper with__mapper_args__ = {'with_polymorphic': '*'}
in Joined Inheritance Relationship.Incorrect SQL query:
Expected behavior
Expected to get SQL statement rather like this:
To Reproduce
https://docs.sqlalchemy.org/en/14/orm/inheritance.html#relationships-with-joined-inheritance
'with_polymorphic': '*'
to__mapper_args__
of parent class as shown here https://docs.sqlalchemy.org/en/14/orm/inheritance_loading.html?highlight=with_polymorphic#setting-with-polymorphic-at-mapper-configuration-timeError
Versions.
Additional context
SQLAlchemy 1.3 has no such error as it produces single-table DELETE statement.
Thank you for your attention.
Have a nice day!
Beta Was this translation helpful? Give feedback.
All reactions