Satchmo/Django: “ProgrammingError: can’t adapt type ‘__proxy__'”

I got the above error when laoding a shipping module in Satchmo, but upon working out the cause, I reckoned it must be a pretty common error these days.

The exception is raised in /django/db/backends/util.py, line 19.
When I checked the local vars of the query.py step, line 2369, I got the following SQL:
[sourcecode language=’sql’]
‘UPDATE “shop_order” SET “site_id” = %s, “contact_id” = %s, “ship_addressee” = %s, “ship_street1” = %s, “ship_street2” = %s, “ship_city” = %s, “ship_state” = %s, “ship_postal_code” = %s, “ship_country” = %s, “bill_addressee” = %s, “bill_street1” = %s, “bill_street2” = %s, “bill_city” = %s, “bill_state” = %s, “bill_postal_code” = %s, “bill_country” = %s, “notes” = NULL, “sub_total” = %s, “total” = %s, “discount_code” = %s, “discount” = %s, “method” = %s, “shipping_description” = %s, “shipping_method” = %s, “shipping_model” = %s, “shipping_cost” = %s, “shipping_discount” = %s, “tax” = %s, “time_stamp” = %s, “status” = %s WHERE “shop_order”.”id” = %s
[/sourcecode]
with the following params:
[sourcecode]
(1, 761, u’abc abc’, u’abc’, u’abcabc’, u’abc’, u'(UK32)’, u’E17 8QG’, u’GB’, u’abc abc’, u’abc’, u’abcabc’, u’abc’, u'(UK32)’, u’E17 8QG’, u’GB’, u’13.2500000000′, u’15.0000000000′, ”, u’0E-10′, u’Online’, ‘Dots Postage and Packing’, , ‘dotship’, u’1.7500000000′, u’0E-10′, u’0E-10′, u’2010-05-05 14:13:07.134682′, u”, 713)
[/sourcecode]

You can see the __proxy__ that shouldn’t be there.

Looking back at my code that provides that particular value, I found I’d used the _() shortcut, which in this file, is bound to ugettext_lazy. Of course, this is the problem! The lazy evaluation isn’t being executed before the query is evaluated.

To fix, either use gettext directly, or change the shortcut for _ from gettext_lazy to gettext.