Opened 10 years ago

Closed 10 years ago

#24978 closed Bug (fixed)

Can't load fixtures with '[' and ']' in path

Reported by: Michał Kowalczyk Owned by: Moritz Sichert
Component: Core (Management commands) Version: 1.8
Severity: Normal Keywords: square brackets fixture path not found
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It's not possible to load a fixture from a path containing [ or ]. The problem is in django/core/management/commands/loaddata.py:206

for candidate in glob.iglob(os.path.join(fixture_dir, fixture_name + '*')):

fixture_dir and fixture_name should be escaped prior to passing it to iglob(), because it interprets some characters as wildcards (see https://docs.python.org/2/library/glob.html).

Note that square brackets are valid characters in filenames in majority of filesystems (including ext and ntfs).

Steps to reproduce:
Set FIXTURE_DIRS in settings.py to anything containing square brackets, e.g. /home/user/test[123]. Try to load any fixture from that directory in your tests.py. It won't find it and will print a warning: No fixture named 'your_fixture_name' found.

Change History (12)

comment:1 by Baptiste Mispelon, 10 years ago

Component: Testing frameworkCore (Management commands)
Triage Stage: UnreviewedAccepted

Hi,

Indeed, I can reproduce that issue.
Python 3.4 gained a glob.escape function that we'll probably want to backport in some way: https://docs.python.org/3/library/glob.html#glob.escape.

Thanks

comment:2 by Moritz Sichert, 10 years ago

Has patch: set
Owner: changed from nobody to Moritz Sichert
Status: newassigned

Added PR.

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

Resolution: fixed
Status: assignedclosed

In 98df288:

Fixed #24978 -- Escaped special characters in loaddata fixture paths

comment:4 by Tim Graham, 10 years ago

Easy pickings: unset
Has patch: unset
Resolution: fixed
Status: closednew

Sorry, but the new test doesn't pass on Windows. Are you able to investigate?

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

In 81aae28:

Refs #24978 -- Skipped an unsupported test on Windows.

comment:6 by Tim Graham, 10 years ago

Resolution: fixed
Status: newclosed

comment:7 by Gagaro, 10 years ago

"?" and "*" are invalid characters on Windows and thus the "fixture?with[special]chars*.json" file cannot be created and cause issue when cloning the repository.

Should I create a new ticket or reopen this one ?

in reply to:  7 comment:8 by Baptiste Mispelon, 10 years ago

Replying to Gagaro:

Should I create a new ticket or reopen this one ?

I would open a new one.

Thanks.

comment:9 by Tim Graham, 10 years ago

Resolution: fixed
Status: closednew

The fix for this one hasn't been released, so it's fine to reopen. I had just skipped the test on Windows, but I guess if we can find characters that work as a regression test but keep Windows happy, that solution would be fine as well.

comment:10 by Gagaro, 10 years ago

"[" and "\]" are enough for the regression test and works on Windows. I did the fix and the pull request is there: https://github.com/django/django/pull/4898

This pull request should be squashed with the other fix to avoid having the bad file in the repository at all.

Last edited 10 years ago by Gagaro (previous) (diff)

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

In 8b7bd62:

Refs #24978 -- Amended test filename to avoid checkout warnings on Windows.

comment:12 by Tim Graham, 10 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top