Opened 10 years ago

Closed 10 years ago

#23468 closed Bug (fixed)

fixtures are imported twice with duplicate FIXTURE_DIRS

Reported by: karyon Owned by: Konrad Świat
Component: Core (Management commands) Version: 1.6
Severity: Normal Keywords:
Cc: konrad.swiat@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

when listing a fixture dir two times in FIXTURE_DIRS, or listing a directory there that is already a default fixture dir of an app, fixtures in these directories are imported twice when running loaddata.

in my project someone accidentally added a default fixture dir to the FIXTURE_DIRS, and it took us a while to figure out why things were imported twice.

on a side node, if fixtures of the same name are in different directories, there are all imported, as opposed to when they are in the same directory (with different extensions). is this intended?

Change History (12)

comment:1 by Aymeric Augustin, 10 years ago

Component: UncategorizedCore (Management commands)
Triage Stage: UnreviewedAccepted

In this situation, Django could raise an ImproperlyConfigured exception, emit a warning (maybe with a check?), or at least deduplicate the list. Loading the fixture twice doesn't make sense.

Regarding your second question, yes, this is the intended behavior.

comment:2 by Konrad Świat, 10 years ago

Owner: changed from nobody to Konrad Świat
Status: newassigned

comment:3 by Konrad Świat, 10 years ago

Has patch: set
Patch needs improvement: set

Work in progress:
https://github.com/kswiat/django/commit/0b96027f697c173f860be2cef18451a715dbe7f1

But I will probably move it to the check framework, because apps are not ready at this point (loading settings). Apps need to be registered in order to get their labels (please correct me if I'm wrong and there is other clean way to do it).

Version 1, edited 10 years ago by Konrad Świat (previous) (next) (diff)

comment:4 by Konrad Świat, 10 years ago

Needs tests: set

comment:5 by Konrad Świat, 10 years ago

Needs tests: unset
Patch needs improvement: unset

Pull request ready.

comment:6 by Claude Paroz, 10 years ago

Wouldn't it be better to check this in the loaddata fixture_dirs method?

Last edited 10 years ago by Konrad Świat (previous) (diff)

comment:7 by Tim Graham, 10 years ago

Patch needs improvement: set

comment:8 by Konrad Świat, 10 years ago

Cc: konrad.swiat@… added

There is new PR with different approach, that checks settings.FIXTURE_DIRS in the loaddata fixture_dirs method. If there are duplicates or default fixture dir of an app, exception is raised.
https://github.com/django/django/pull/3447
Or maybe it should emit a warning instead of raising?

I mistakenly edited comment:6 by claudep. Sorry for that. Is there a problem with trac's permissions?

Last edited 10 years ago by Konrad Świat (previous) (diff)

comment:9 by Konrad Świat, 10 years ago

Patch needs improvement: unset

comment:10 by Berker Peksag, 10 years ago

Needs documentation: set
Patch needs improvement: set

comment:11 by Konrad Świat, 10 years ago

Needs documentation: unset
Patch needs improvement: unset

I added release notes for 1.7.2, 1.8 and improved patch.

comment:12 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 934a16dc93a5f46f965ba299dbd543703d32d493:

Fixed #23468 -- Added checks for duplicate fixtures directories in loaddata.

If settings.FIXTURE_DIRS contains duplicates or a default fixture
directory (app_name/fixtures), ImproperlyConfigured is raised.

Thanks to Berker Peksag and Tim Graham for review.

Note: See TracTickets for help on using tickets.
Back to Top