Browse Source

Register PickledObject otherwise psycopg2 will throw a can't adapt error since the data type is unknown.

Brian Rosner 16 years ago
parent
commit
60e333ffd2
1 changed files with 8 additions and 0 deletions
  1. 8 0
      celery/fields.py

+ 8 - 0
celery/fields.py

@@ -4,6 +4,7 @@ Custom Django Model Fields.
 
 """
 from django.db import models
+from django.conf import settings
 
 try:
     import cPickle as pickle
@@ -18,6 +19,13 @@ class PickledObject(str):
     pass
 
 
+if settings.DATABASE_ENGINE == "postgresql_psycopg2":
+    import psycopg2.extensions
+    # register PickledObject as a QuotedString otherwise we will see
+    # can't adapt errors from psycopg2.
+    psycopg2.extensions.register_adapter(PickledObject, psycopg2.extensions.QuotedString)
+
+
 class PickledObjectField(models.Field):
     """A field that automatically pickles/unpickles its value."""
     __metaclass__ = models.SubfieldBase