diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2011-04-26 16:49:32 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2011-04-26 16:49:32 +0000 |
| commit | 930371e91b03f91691fa5e2e4f428cb72469e191 (patch) | |
| tree | 05c740455fc84e8341a1efa6007ef517374e58ce /django | |
| parent | 1b6670dd590ef8f235166ce966d28ac49f322c54 (diff) | |
Fixed #15889 -- when trying to access to access a serializer that doesn't exist, raise a new SerializerDoesNotExist exception. Thanks to Mathieu Agopian for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16104 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/serializers/__init__.py | 7 | ||||
| -rw-r--r-- | django/core/serializers/base.py | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/django/core/serializers/__init__.py b/django/core/serializers/__init__.py index 7afc94c1d0..09bcb651d5 100644 --- a/django/core/serializers/__init__.py +++ b/django/core/serializers/__init__.py @@ -18,6 +18,7 @@ To add your own serializers, use the SERIALIZATION_MODULES setting:: from django.conf import settings from django.utils import importlib +from django.core.serializers.base import SerializerDoesNotExist # Built-in serializers BUILTIN_SERIALIZERS = { @@ -60,11 +61,15 @@ def unregister_serializer(format): "Unregister a given serializer. This is not a thread-safe operation." if not _serializers: _load_serializers() + if format not in _serializers: + raise SerializerDoesNotExist(format) del _serializers[format] def get_serializer(format): if not _serializers: _load_serializers() + if format not in _serializers: + raise SerializerDoesNotExist(format) return _serializers[format].Serializer def get_serializer_formats(): @@ -80,6 +85,8 @@ def get_public_serializer_formats(): def get_deserializer(format): if not _serializers: _load_serializers() + if format not in _serializers: + raise SerializerDoesNotExist(format) return _serializers[format].Deserializer def serialize(format, queryset, **options): diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index cdcc7fa36a..6afaf216a8 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -8,6 +8,10 @@ from django.db import models from django.utils.encoding import smart_str, smart_unicode from django.utils import datetime_safe +class SerializerDoesNotExist(KeyError): + """The requested serializer was not found.""" + pass + class SerializationError(Exception): """Something bad happened during serialization.""" pass |
