diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index ce7cdb3179..91af84e9ca 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -40,6 +40,8 @@ def Deserializer(stream_or_string, **options): try: for obj in PythonDeserializer(simplejson.load(stream), **options): yield obj + except GeneratorExit: + raise except Exception, e: # Map to deserializer error raise DeserializationError(e) diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py index 1f4f967ebb..7a508da5d7 100644 --- a/django/core/serializers/pyyaml.py +++ b/django/core/serializers/pyyaml.py @@ -55,6 +55,8 @@ def Deserializer(stream_or_string, **options): try: for obj in PythonDeserializer(yaml.safe_load(stream), **options): yield obj + except GeneratorExit: + raise except Exception, e: # Map to deserializer error raise DeserializationError(e) diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py index efad176eaa..5abff6345f 100644 --- a/tests/regressiontests/serializers_regress/tests.py +++ b/tests/regressiontests/serializers_regress/tests.py @@ -17,12 +17,18 @@ try: except ImportError: from StringIO import StringIO +try: + import yaml +except ImportError: + yaml = None + from django.core import serializers from django.core.serializers import SerializerDoesNotExist from django.core.serializers.base import DeserializationError from django.db import connection, models from django.test import TestCase from django.utils.functional import curry +from django.utils.unittest import skipUnless from .models import (BooleanData, CharData, DateData, DateTimeData, EmailData, FileData, FilePathData, DecimalData, FloatData, IntegerData, IPAddressData, @@ -396,6 +402,7 @@ class SerializerTests(TestCase): for obj in serializers.deserialize("json", """[{"pk":1}"""): pass + @skipUnless(yaml, "PyYAML not installed") def test_yaml_deserializer_exception(self): with self.assertRaises(DeserializationError): for obj in serializers.deserialize("yaml", "{"):