Opened 3 years ago

Closed 20 months ago

#18213 closed New feature (fixed)

loaddata should allow empty fixtures

Reported by: lsaffre Owned by: haxoza
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: renatooliveira, 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 renatooliveira 3 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 3 years ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 3 years ago by renatooliveira

  • Owner changed from nobody to renatooliveira

Changed 3 years ago by renatooliveira

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 3 years ago by renatooliveira

  • Cc renatooliveira added
  • Has patch set

comment:4 Changed 3 years ago by claudep

  • Needs tests set
  • Patch needs improvement set

I think that at least a warning should be output.

comment:5 Changed 2 years ago by renatooliveira

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

comment:6 Changed 2 years ago by haxoza

  • Owner changed from renatooliveira to haxoza
  • Status changed from new to assigned

comment:7 Changed 2 years ago by haxoza

  • 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 2 years ago by aaugustin

  • Component changed from Uncategorized to Core (Management commands)

comment:9 Changed 21 months ago by timo

  • Cc timograham@… added
  • Patch needs improvement set

No longer merges cleanly.

comment:10 Changed 20 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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