Changeset 9357
- Timestamp:
- 11/06/08 05:19:13 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/management/commands/loaddata.py
r9110 r9357 36 36 fixture_count = 0 37 37 object_count = 0 38 objects_per_fixture = []39 38 models = set() 40 39 … … 104 103 else: 105 104 fixture_count += 1 106 objects_ per_fixture.append(0)105 objects_in_fixture = 0 107 106 if verbosity > 0: 108 107 print "Installing %s fixture '%s' from %s." % \ … … 111 110 objects = serializers.deserialize(format, fixture) 112 111 for obj in objects: 113 object_count += 1 114 objects_per_fixture[-1] += 1 112 objects_in_fixture += 1 115 113 models.add(obj.object.__class__) 116 114 obj.save() 115 object_count += objects_in_fixture 117 116 label_found = True 118 117 except (SystemExit, KeyboardInterrupt): … … 132 131 return 133 132 fixture.close() 133 134 # If the fixture we loaded contains 0 objects, assume that an 135 # error was encountered during fixture loading. 136 if objects_in_fixture == 0: 137 sys.stderr.write( 138 self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)" % 139 (fixture_name))) 140 transaction.rollback() 141 transaction.leave_transaction_management() 142 return 134 143 except: 135 144 if verbosity > 1: 136 145 print "No %s fixture '%s' in %s." % \ 137 146 (format, fixture_name, humanize(fixture_dir)) 138 139 140 # If any of the fixtures we loaded contain 0 objects, assume that an141 # error was encountered during fixture loading.142 if 0 in objects_per_fixture:143 sys.stderr.write(144 self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)" %145 (fixture_name)))146 transaction.rollback()147 transaction.leave_transaction_management()148 return149 147 150 148 # If we found even one object in a fixture, we need to reset the django/trunk/tests/regressiontests/fixtures_regress/models.py
r8515 r9357 8 8 latin_name = models.CharField(max_length=150) 9 9 count = models.IntegerField() 10 10 11 11 def __unicode__(self): 12 12 return self.common_name … … 57 57 title = models.CharField(max_length=255) 58 58 channels = models.ManyToManyField(Channel) 59 59 60 60 class Meta: 61 61 ordering = ('id',) … … 114 114 No fixture data found for 'bad_fixture2'. (File format may be invalid.) 115 115 116 # Loading a fixture file with no data returns an error 117 >>> management.call_command('loaddata', 'empty', verbosity=0) 118 No fixture data found for 'empty'. (File format may be invalid.) 119 120 # If any of the fixtures contain an error, loading is aborted 121 # (Regression for #9011 - error message is correct) 122 >>> management.call_command('loaddata', 'bad_fixture2', 'animal', verbosity=0) 123 No fixture data found for 'bad_fixture2'. (File format may be invalid.) 124 116 125 >>> sys.stderr = savestderr 117 126 … … 124 133 125 134 ############################################### 126 # Test for ticket #7572 -- MySQL has a problem if the same connection is 135 # Test for ticket #7572 -- MySQL has a problem if the same connection is 127 136 # used to create tables, load data, and then query over that data. 128 137 # To compensate, we close the connection after running loaddata.
