Opened 12 years ago

Closed 11 years ago

#18213 closed New feature (fixed)

loaddata should allow empty fixtures

Reported by: Luc Saffre Owned by: Przemek Lewandowski
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Renato Oliveira, timograham@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

The loading management command does the following test:

# If the fixture we loaded contains 0 objects, assume that an
# error was encountered during fixture loading.
if objects_in_fixture == 0:
    self.stderr.write(
        self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)\n" %
            (fixture_name)))
    if commit:
        transaction.rollback(using=using)
        transaction.leave_transaction_management(using=using)
    return

I suggest to either remove this test or to add a setting to disable it.
Because a fixture returning no objects is a perfectly possible edge case (depending on some local configuration settings) when using Python fixtures <http://lino.saffre-rumma.net/topics/dumpy.html>.

Attachments (1)

ticket18213.diff (1.0 KB ) - added by Renato Oliveira 12 years ago.
I just removed the test. But, if the best way is to create a setting to disable it whenever you want, how would it be?

Download all attachments as: .zip

Change History (11)

comment:1 by Anssi Kääriäinen, 12 years ago

Triage Stage: UnreviewedAccepted

I don't see any reason why an empty fixture must be an error.

comment:2 by Renato Oliveira, 12 years ago

Owner: changed from nobody to Renato Oliveira

by Renato Oliveira, 12 years ago

Attachment: ticket18213.diff added

I just removed the test. But, if the best way is to create a setting to disable it whenever you want, how would it be?

comment:3 by Renato Oliveira, 12 years ago

Cc: Renato Oliveira added
Has patch: set

comment:4 by Claude Paroz, 12 years ago

Needs tests: set
Patch needs improvement: set

I think that at least a warning should be output.

comment:5 by Renato Oliveira, 11 years ago

Sorry about the delay, I'll send the patch this week.

comment:6 by Przemek Lewandowski, 11 years ago

Owner: changed from Renato Oliveira to Przemek Lewandowski
Status: newassigned

comment:7 by Przemek Lewandowski, 11 years ago

Needs tests: unset
Patch needs improvement: unset

Error changed to warning and some updates in tests. https://github.com/django/django/pull/799

comment:8 by Aymeric Augustin, 11 years ago

Component: UncategorizedCore (Management commands)

comment:9 by Tim Graham, 11 years ago

Cc: timograham@… added
Patch needs improvement: set

No longer merges cleanly.

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

Resolution: fixed
Status: assignedclosed

In 382c53d7d88da70a3645c6db063995382f61dc45:

Fixed #18213 -- Allowed empty fixtures (emit a warning rather than raising an exception).

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