Opened 9 years ago
Closed 9 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 , 9 years ago
Component: | Testing framework → Core (Management commands) |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 9 years ago
Easy pickings: | unset |
---|---|
Has patch: | unset |
Resolution: | fixed |
Status: | closed → new |
Sorry, but the new test doesn't pass on Windows. Are you able to investigate?
comment:6 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
follow-up: 8 comment:7 by , 9 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 ?
comment:8 by , 9 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 , 9 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
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 , 9 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.
comment:12 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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