Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #7676 -- Modified serializer registration to be thread safe. Th…

…anks to mrts for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8370 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0c115f12d742429ca32b4bcce787873eda4ffccc 1 parent 188f131
@freakboy3742 freakboy3742 authored
Showing with 24 additions and 7 deletions.
  1. +24 −7 django/core/serializers/__init__.py
View
31 django/core/serializers/__init__.py
@@ -34,13 +34,27 @@
_serializers = {}
-def register_serializer(format, serializer_module):
- """Register a new serializer by passing in a module name."""
+def register_serializer(format, serializer_module, serializers=None):
+ """"Register a new serializer.
+
+ ``serializer_module`` should be the fully qualified module name
+ for the serializer.
+
+ If ``serializers`` is provided, the registration will be added
+ to the provided dictionary.
+
+ If ``serializers`` is not provided, the registration will be made
+ directly into the global register of serializers. Adding serializers
+ directly is not a thread-safe operation.
+ """
module = __import__(serializer_module, {}, {}, [''])
- _serializers[format] = module
-
+ if serializers is None:
+ _serializers[format] = module
+ else:
+ serializers[format] = module
+
def unregister_serializer(format):
- """Unregister a given serializer"""
+ "Unregister a given serializer. This is not a thread-safe operation."
del _serializers[format]
def get_serializer(format):
@@ -88,8 +102,11 @@ def _load_serializers():
that user code has a chance to (e.g.) set up custom settings without
needing to be careful of import order.
"""
+ global _serializers
+ serializers = {}
for format in BUILTIN_SERIALIZERS:
- register_serializer(format, BUILTIN_SERIALIZERS[format])
+ register_serializer(format, BUILTIN_SERIALIZERS[format], serializers)
if hasattr(settings, "SERIALIZATION_MODULES"):
for format in settings.SERIALIZATION_MODULES:
- register_serializer(format, settings.SERIALIZATION_MODULES[format])
+ register_serializer(format, settings.SERIALIZATION_MODULES[format], serializers)
+ _serializers = serializers
Please sign in to comment.
Something went wrong with that request. Please try again.