[Mpuls-commits] r5963 - base/branches/2.0.19/mpulsweb/lib
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu May 24 13:56:45 CEST 2012
Author: roland
Date: 2012-05-24 13:56:45 +0200 (Thu, 24 May 2012)
New Revision: 5963
Modified:
base/branches/2.0.19/mpulsweb/lib/db.py
Log:
Backported fix for issue3023
Modified: base/branches/2.0.19/mpulsweb/lib/db.py
===================================================================
--- base/branches/2.0.19/mpulsweb/lib/db.py 2012-05-23 13:17:30 UTC (rev 5962)
+++ base/branches/2.0.19/mpulsweb/lib/db.py 2012-05-24 11:56:45 UTC (rev 5963)
@@ -30,6 +30,7 @@
import logging
from contextlib import contextmanager
+import decimal
import psycopg2 as dbapi
import psycopg2.extensions
@@ -47,6 +48,20 @@
# implementations.
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
+# Work around a subtle defect in psycopg2. When running two Python
+# sub-interpreters in the same process the dictionary implementing the
+# adaptation protocol in psycopg is shared between the interpreters.
+# However, each interpreter has its own Decimal class which leads to
+# adaptation failures when trying to use Decimal values in SQL queries.
+# psycopg raises ProgrammingError with a message containing "can't
+# adapt". We work around this problem by always registering the Decimal
+# type of the current interpreter as described in the psycopg ticket for
+# this defect. See also mpuls/issue3023.
+# This defect has been fixed with psycopg 2.4.3, so we can remove this
+# work-around again when it's no longer needed.
+# psycopg ticket:
+# http://psycopg.lighthouseapp.com/projects/62710/tickets/52-cant-adapt-type-decimal
+psycopg2.extensions.register_adapter(decimal.Decimal, psycopg2._psycopg.Decimal)
db = StackedObjectProxy(name="mpuls.db")
More information about the Mpuls-commits
mailing list