#18990 closed Bug (fixed)
'manage.py loaddata' does not report if the loading file does not exist
Reported by: | sergzach | Owned by: | senko |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.4 |
Severity: | Normal | Keywords: | loaddata |
Cc: | Türker Sezer, d1fffuz0r@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the next case the file ProductCategory2.json does not exist but the loaddata utility does not report about it. It reports that 0 objects installed from 0 fixtures instead.
v11162:/www/lavka/dargent# python manage.py loaddata /root/models/ProductCategory2.json Installed 0 object(s) from 0 fixture(s)
There are files in /root/lavka/:
v11162:/www/lavka/dargent# ls /root/models/ Country.json Producer.json ProductCategory.json
Attachments (3)
Change History (18)
comment:1 by , 12 years ago
Component: | Core (Other) → Core (Management commands) |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 12 years ago
Needs tests: | set |
---|
by , 12 years ago
Attachment: | 18990_tests.patch added |
---|
follow-up: 6 comment:5 by , 12 years ago
Patch needs improvement: | set |
---|
I think we only want to raise an error when a single fixture file was specified no valid fixture files were found in a dir - which I believe means checking at this point:
if os.path.isabs(fixture_name): fixture_dirs = [fixture_name]
Since we have specified a single file - and it does not exist - raising an actual CommandError is probably what is desired. The tests should check that this is raised using assertRaises.
comment:6 by , 12 years ago
Hmm. Every time the commands "loaddata" and "flush" trying to load the 'initial_data' fixture, how be with it. Ignore? Because that be generate the errors. Setup "--no-initial-data" default value to False can break backward compatibilities
django/core/management/commands/syncdb.py:
# Load initial_data fixtures (unless that has been disabled) if load_initial_data: call_command('loaddata', 'initial_data', verbosity=verbosity, database=db, skip_validation=True)
Sorry for my English
comment:7 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 12 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
@ptone: that would still hide an error when you specify a single fixture (but not an absolute path), eg: ./manage.py loaddata myfixture.json (it's not an absolute path and wouldn't register here).
Reading the source, it seems to me that the name "initial_data" is special to Django (syncdb and flush hardcode it), so a solution I tried was to not raise the CommandError if the fixture name is "initial_data". I don't like the part that it's now hardcoded in another place - is there a good place to put this in, except settings (since we probably don't want it to be user-settable).
Another possible solution would be to raise the error unconditionally and catch it in flush/syncdb, but that would catch *any* CommandError loaddata might raise, which is again probably not what we want.
Based on the above, I think this approach makes sense - here's a pull request with a fix and updated tests for it: https://github.com/django/django/pull/1134
Please let me know if this makes sense.
comment:9 by , 12 years ago
PR 1134 breaks current functionality. If the list of files is generated with a script this now bails out on first not found file. It might be a good idea, but nonetheless it is backward incompatible change.
I think it would be better to just list the not found files and continue.
comment:11 by , 12 years ago
Another good comment by derega via IRC: the output from the warnings looks a bit unfriendly:
(django-dev)[tachyon:djangotest]$ python manage.py loaddata asd.json as.json /home/senko/.virtualenvs/django-dev/lib/python2.7/django/core/management/commands/loaddata.py:173: UserWarning: No fixture named 'asd' found. warnings.warn("No fixture named '%s' found." % fixture_name) /home/senko/.virtualenvs/django-dev/lib/python2.7/django/core/management/commands/loaddata.py:173: UserWarning: No fixture named 'as' found. warnings.warn("No fixture named '%s' found." % fixture_name) Installed 0 object(s) from 0 fixture(s)
comment:13 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
While the "0 fixture(s)" is accurate - I agree a more helpful message/error could be displayed.