Ticket #18827: 18827-1.diff

File 18827-1.diff, 900 bytes (added by claudep, 3 years ago)

Use pkgutil to list packages

  • django/db/utils.py

    diff --git a/django/db/utils.py b/django/db/utils.py
    index 0ce09ba..9f889ad 100644
    a b  
    11import os
     2import pkgutil
    23from threading import local
    34
    45from django.conf import settings
    def load_backend(backend_name): 
    2829        # listing all possible (built-in) database backends.
    2930        backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
    3031        try:
    31             available_backends = [f for f in os.listdir(backend_dir)
    32                     if os.path.isdir(os.path.join(backend_dir, f))
    33                     and not f.startswith('.')]
     32            available_backends = [name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
     33                    if ispkg]
    3434        except EnvironmentError:
    3535            available_backends = []
    3636        full_notation = backend_name.startswith('django.db.backends.')
Back to Top