Ticket #8245: Misleading-AlreadyRegistered-03.diff

File Misleading-AlreadyRegistered-03.diff, 985 bytes (added by , 16 years ago)

Simply copy the registry before import and restore on exception. This prevents AlreadyRegistered and NotRegistered exceptions.

  • django/contrib/admin/__init__.py

     
    99    may want.
    1010    """
    1111    import imp
     12    import copy
    1213    from django.conf import settings
    1314    for app in settings.INSTALLED_APPS:
    1415        try:
     
    1617        except ImportError:
    1718            # there is no app admin.py, skip it
    1819            continue
    19         __import__("%s.admin" % app)
     20        try:
     21            model_registry_before_import = copy.copy(site._registry)
     22            __import__("%s.admin" % app)
     23        except:
     24            # Reset the model registry to the state before the last import as this import will have to reoccur
     25            # on the next request and this could raise NotRegistered and AlreadyRegistered exceptions (see #8245).
     26            site._registry = model_registry_before_import
     27            raise
Back to Top