Opened 4 years ago

Closed 3 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: master
Severity: Normal Keywords:
Cc: Renato dos Santos 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 dos Santos Oliveira 4 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 Changed 4 years ago by Anssi Kääriäinen

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

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

comment:2 Changed 4 years ago by Renato dos Santos Oliveira

Owner: changed from nobody to Renato dos Santos Oliveira

Changed 4 years ago by Renato dos Santos Oliveira

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 Changed 4 years ago by Renato dos Santos Oliveira

Cc: Renato dos Santos Oliveira added
Has patch: set

comment:4 Changed 4 years ago by Claude Paroz

Needs tests: set
Patch needs improvement: set

I think that at least a warning should be output.

comment:5 Changed 4 years ago by Renato dos Santos Oliveira

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

comment:6 Changed 4 years ago by Przemek Lewandowski

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

comment:7 Changed 4 years ago by Przemek Lewandowski

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 Changed 4 years ago by Aymeric Augustin

Component: UncategorizedCore (Management commands)

comment:9 Changed 3 years ago by Tim Graham

Cc: timograham@… added
Patch needs improvement: set

No longer merges cleanly.

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

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