Ticket #18196: 18196-1.diff

File 18196-1.diff, 3.7 KB (added by Claude Paroz, 7 years ago)

More precise exception catching

  • django/core/management/commands/loaddata.py

    diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
    index 078fd6f..9a827a6 100644
    a b class Command(BaseCommand): 
    193193                                    loaded_object_count += loaded_objects_in_fixture
    194194                                    fixture_object_count += objects_in_fixture
    195195                                    label_found = True
     196                                except Exception as e:
     197                                    if not isinstance(e, CommandError):
     198                                        e.args = ("Problem installing fixture '%s': %s" % (full_path, e),)
     199                                    raise
    196200                                finally:
    197201                                    fixture.close()
    198202
    class Command(BaseCommand): 
    206210            # Since we disabled constraint checks, we must manually check for
    207211            # any invalid keys that might have been added
    208212            table_names = [model._meta.db_table for model in models]
    209             connection.check_constraints(table_names=table_names)
     213            try:
     214                connection.check_constraints(table_names=table_names)
     215            except Exception as e:
     216                e.args = ("Problem installing fixtures: %s" % e,)
     217                raise
    210218
    211219        except (SystemExit, KeyboardInterrupt):
    212220            raise
    class Command(BaseCommand): 
    214222            if commit:
    215223                transaction.rollback(using=using)
    216224                transaction.leave_transaction_management(using=using)
    217             if not isinstance(e, CommandError):
    218                 e.args = ("Problem installing fixture '%s': %s" % (full_path, e),)
    219225            raise
    220226
    221227        # If we found even one object in a fixture, we need to reset the
  • django/test/signals.py

    diff --git a/django/test/signals.py b/django/test/signals.py
    index 81808df..3766fae 100644
    a b import time 
    44from django.conf import settings
    55from django.db import connections
    66from django.dispatch import receiver, Signal
    7 from django.template import context
    87from django.utils import timezone
    98
    109template_rendered = Signal(providing_args=["template", "context"])
    def update_connections_time_zone(**kwargs): 
    4342
    4443
    4544@receiver(setting_changed)
    46 def clear_context_processors_cache(**kwargs):
     45def clear_global_variables(**kwargs):
    4746    if kwargs['setting'] == 'TEMPLATE_CONTEXT_PROCESSORS':
     47        from django.template import context
    4848        context._standard_context_processors = None
     49    elif kwargs['setting'] == 'SERIALIZATION_MODULES':
     50        from django.core import serializers
     51        serializers._serializers = {}
  • tests/regressiontests/fixtures_regress/tests.py

    diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
    index c0b811b..1bba237 100644
    a b class TestFixtures(TestCase): 
    126126                commit=False,
    127127            )
    128128
     129    @override_settings(SERIALIZATION_MODULES={'unkn': 'unexistent.path'})
     130    def test_unimportable_serializer(self):
     131        """
     132        Test that failing serializer import raises the proper error
     133        """
     134        with self.assertRaisesRegexp(ImportError,
     135                "No module named unexistent.path"):
     136            management.call_command(
     137                'loaddata',
     138                'bad_fixture1.unkn',
     139                verbosity=0,
     140                commit=False,
     141            )
     142
    129143    def test_invalid_data(self):
    130144        """
    131145        Test for ticket #4371 -- Loading a fixture file with invalid data
Back to Top