浏览代码

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

Brian Rosner 16 年之前
父节点
当前提交
60e333ffd2
共有 1 个文件被更改,包括 8 次插入0 次删除
  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