Loading django/core/management/commands/loaddata.py +9 −3 Original line number Diff line number Diff line Loading @@ -196,6 +196,10 @@ class Command(BaseCommand): loaded_object_count += loaded_objects_in_fixture fixture_object_count += objects_in_fixture label_found = True except Exception as e: if not isinstance(e, CommandError): e.args = ("Problem installing fixture '%s': %s" % (full_path, e),) raise finally: fixture.close() Loading @@ -209,7 +213,11 @@ class Command(BaseCommand): # Since we disabled constraint checks, we must manually check for # any invalid keys that might have been added table_names = [model._meta.db_table for model in models] try: connection.check_constraints(table_names=table_names) except Exception as e: e.args = ("Problem installing fixtures: %s" % e,) raise except (SystemExit, KeyboardInterrupt): raise Loading @@ -217,8 +225,6 @@ class Command(BaseCommand): if commit: transaction.rollback(using=using) transaction.leave_transaction_management(using=using) if not isinstance(e, CommandError): e.args = ("Problem installing fixture '%s': %s" % (full_path, e),) raise # If we found even one object in a fixture, we need to reset the Loading django/test/signals.py +8 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ import time from django.conf import settings from django.db import connections from django.dispatch import receiver, Signal from django.template import context from django.utils import timezone template_rendered = Signal(providing_args=["template", "context"]) Loading Loading @@ -48,9 +47,17 @@ def update_connections_time_zone(**kwargs): @receiver(setting_changed) def clear_context_processors_cache(**kwargs): if kwargs['setting'] == 'TEMPLATE_CONTEXT_PROCESSORS': from django.template import context context._standard_context_processors = None @receiver(setting_changed) def clear_serializers_cache(**kwargs): if kwargs['setting'] == 'SERIALIZATION_MODULES': from django.core import serializers serializers._serializers = {} @receiver(setting_changed) def language_changed(**kwargs): if kwargs['setting'] in ('LOCALE_PATHS', 'LANGUAGE_CODE'): Loading tests/regressiontests/fixtures_regress/tests.py +14 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,20 @@ class TestFixtures(TestCase): commit=False, ) @override_settings(SERIALIZATION_MODULES={'unkn': 'unexistent.path'}) def test_unimportable_serializer(self): """ Test that failing serializer import raises the proper error """ with self.assertRaisesRegexp(ImportError, "No module named unexistent.path"): management.call_command( 'loaddata', 'bad_fixture1.unkn', verbosity=0, commit=False, ) def test_invalid_data(self): """ Test for ticket #4371 -- Loading a fixture file with invalid data Loading Loading
django/core/management/commands/loaddata.py +9 −3 Original line number Diff line number Diff line Loading @@ -196,6 +196,10 @@ class Command(BaseCommand): loaded_object_count += loaded_objects_in_fixture fixture_object_count += objects_in_fixture label_found = True except Exception as e: if not isinstance(e, CommandError): e.args = ("Problem installing fixture '%s': %s" % (full_path, e),) raise finally: fixture.close() Loading @@ -209,7 +213,11 @@ class Command(BaseCommand): # Since we disabled constraint checks, we must manually check for # any invalid keys that might have been added table_names = [model._meta.db_table for model in models] try: connection.check_constraints(table_names=table_names) except Exception as e: e.args = ("Problem installing fixtures: %s" % e,) raise except (SystemExit, KeyboardInterrupt): raise Loading @@ -217,8 +225,6 @@ class Command(BaseCommand): if commit: transaction.rollback(using=using) transaction.leave_transaction_management(using=using) if not isinstance(e, CommandError): e.args = ("Problem installing fixture '%s': %s" % (full_path, e),) raise # If we found even one object in a fixture, we need to reset the Loading
django/test/signals.py +8 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ import time from django.conf import settings from django.db import connections from django.dispatch import receiver, Signal from django.template import context from django.utils import timezone template_rendered = Signal(providing_args=["template", "context"]) Loading Loading @@ -48,9 +47,17 @@ def update_connections_time_zone(**kwargs): @receiver(setting_changed) def clear_context_processors_cache(**kwargs): if kwargs['setting'] == 'TEMPLATE_CONTEXT_PROCESSORS': from django.template import context context._standard_context_processors = None @receiver(setting_changed) def clear_serializers_cache(**kwargs): if kwargs['setting'] == 'SERIALIZATION_MODULES': from django.core import serializers serializers._serializers = {} @receiver(setting_changed) def language_changed(**kwargs): if kwargs['setting'] in ('LOCALE_PATHS', 'LANGUAGE_CODE'): Loading
tests/regressiontests/fixtures_regress/tests.py +14 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,20 @@ class TestFixtures(TestCase): commit=False, ) @override_settings(SERIALIZATION_MODULES={'unkn': 'unexistent.path'}) def test_unimportable_serializer(self): """ Test that failing serializer import raises the proper error """ with self.assertRaisesRegexp(ImportError, "No module named unexistent.path"): management.call_command( 'loaddata', 'bad_fixture1.unkn', verbosity=0, commit=False, ) def test_invalid_data(self): """ Test for ticket #4371 -- Loading a fixture file with invalid data Loading