Cartridge Sale update mysql problem

Showing 1-2 of 2 messages
Cartridge Sale update mysql problem dodgyville 9/18/11 7:35 PM

When creating a Sale object in the mezzanine admin, I get:

OperationalError at /admin/shop/sale/3/
(1093, "You can't specify target table 'shop_product' for update in
FROM clause")

In cartridge/shop/ in around line 731 (your version
may vary).

Tthere is a known limitation with mysql that won't let you use the
same table for both the subquery FROM clause and the update target.

My hack solution is to "downgrade" that line from an update to a slow
loop through and save when encountering the mysql error, but a much
better solution would be to rewrite the SQL update command to work in
mysql too.

diff -r a68623abf7a5 cartridge/shop/
--- a/cartridge/shop/        Fri Sep 16 14:52:32 2011 +1000
+++ b/cartridge/shop/        Mon Sep 19 12:33:30 2011 +1000
@@ -10,6 +10,7 @@
 from django.db.models.signals import post_save
 from django.dispatch import receiver
 from django.utils.translation import ugettext_lazy as _
+from _mysql_exceptions import OperationalError

 from countries.models import Country

@@ -729,6 +730,13 @@
                               "sale_to": self.valid_to,
                               "sale_from": self.valid_from}
+                except OperationalError: #work around for mysql
+                    try:
+                        for priced_object in
+                            priced_object.__dict__.update(**update)
+                    except Warning:
+                        pass
                 except Warning:

Re: [mezzanine-users] Cartridge Sale update mysql problem Stephen McDonald 9/20/11 1:22 PM
Thanks Luke - if you'd like to commit a fix for this I'll merge it in. Might need a check around the import as well in case the mysql libs aren't installed (eg for people using postgres)--
Stephen McDonald