Inserting/updating an inline-edited object that has order_with_respect_to enabled results in the following traceback:
Traceback (most recent call last):
[snip]
File "lib/django/django/db/models/base.py" in save
File "lib/django/django/db/backends/util.py" in execute
File "lib/django/django/db/backends/mysql/base.py" in execute
File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py" in execute
137. self.errorhandler(self, exc, value)
File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py" in defaulterrorhandler
33. raise errorclass, errorvalue
OperationalError at /admin/products/productlocalization/4445/
(1093, "You can't specify target table 'products_download' for update in FROM clause")
The SQL query causing this problem is:
INSERT INTO `products_download` (`product_id`,`title`,`file`,`type`,`_order`)
VALUES (%s,%s,%s,%s,(SELECT COUNT(*) FROM `products_download` WHERE `product_id` = %s))
Apparently this is due to a limitation of MySQL regarding subqueries, documented on the page describing the UPDATE statement:
Currently, you cannot update a table and select from the same table in a subquery.