Fixed #25246 -- Guarded against duplicate paths in AppConfig.
This commit is contained in:
parent
722bf23518
commit
6a98396b9d
|
@ -62,6 +62,10 @@ class AppConfig(object):
|
||||||
filename = getattr(module, '__file__', None)
|
filename = getattr(module, '__file__', None)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
paths = [os.path.dirname(filename)]
|
paths = [os.path.dirname(filename)]
|
||||||
|
else:
|
||||||
|
# For unknown reasons, sometimes the list returned by __path__
|
||||||
|
# contains duplicates that must be removed (#25246).
|
||||||
|
paths = list(set(paths))
|
||||||
if len(paths) > 1:
|
if len(paths) > 1:
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"The app module %r has multiple filesystem locations (%r); "
|
"The app module %r has multiple filesystem locations (%r); "
|
||||||
|
|
|
@ -365,6 +365,14 @@ class AppConfigTests(SimpleTestCase):
|
||||||
with self.assertRaises(ImproperlyConfigured):
|
with self.assertRaises(ImproperlyConfigured):
|
||||||
AppConfig('label', Stub(__path__=['a', 'b']))
|
AppConfig('label', Stub(__path__=['a', 'b']))
|
||||||
|
|
||||||
|
def test_duplicate_dunder_path_no_dunder_file(self):
|
||||||
|
"""
|
||||||
|
If the __path__ attr contains duplicate paths and there is no
|
||||||
|
__file__, they duplicates should be deduplicated (#25246).
|
||||||
|
"""
|
||||||
|
ac = AppConfig('label', Stub(__path__=['a', 'a']))
|
||||||
|
self.assertEqual(ac.path, 'a')
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(six.PY3, "Namespace packages sans __init__.py were added in Python 3.3")
|
@skipUnless(six.PY3, "Namespace packages sans __init__.py were added in Python 3.3")
|
||||||
class NamespacePackageAppTests(SimpleTestCase):
|
class NamespacePackageAppTests(SimpleTestCase):
|
||||||
|
|
Loading…
Reference in New Issue