From 903ac2f36439ab33039be077f474c23a3b72bf78 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 23 Aug 2022 12:05:27 +0200 Subject: [PATCH] Fixed #33949 -- Fixed fixture dirs duplicates with Path instances. --- django/core/management/commands/loaddata.py | 2 +- tests/fixtures_regress/tests.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index ac97f13161..6fae255407 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -367,7 +367,7 @@ class Command(BaseCommand): for app_config in apps.get_app_configs(): app_label = app_config.label app_dir = os.path.join(app_config.path, "fixtures") - if app_dir in fixture_dirs: + if app_dir in [str(d) for d in fixture_dirs]: raise ImproperlyConfigured( "'%s' is a default fixture directory for the '%s' app " "and cannot be listed in settings.FIXTURE_DIRS." diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py index 8c9228f675..ff796feb94 100644 --- a/tests/fixtures_regress/tests.py +++ b/tests/fixtures_regress/tests.py @@ -569,6 +569,20 @@ class TestFixtures(TestCase): with self.assertRaisesMessage(ImproperlyConfigured, msg): management.call_command("loaddata", "absolute.json", verbosity=0) + @override_settings(FIXTURE_DIRS=[Path(_cur_dir) / "fixtures"]) + def test_fixture_dirs_with_default_fixture_path_as_pathlib(self): + """ + settings.FIXTURE_DIRS cannot contain a default fixtures directory + for application (app/fixtures) in order to avoid repeated fixture loading. + """ + msg = ( + "'%s' is a default fixture directory for the '%s' app " + "and cannot be listed in settings.FIXTURE_DIRS." + % (os.path.join(_cur_dir, "fixtures"), "fixtures_regress") + ) + with self.assertRaisesMessage(ImproperlyConfigured, msg): + management.call_command("loaddata", "absolute.json", verbosity=0) + @override_settings( FIXTURE_DIRS=[ os.path.join(_cur_dir, "fixtures_1"),