mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
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
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user