Django

Code

Changeset 7145

Show
Ignore:
Timestamp:
02/22/08 06:50:10 (7 months ago)
Author:
russellm
Message:

Fixed #6436 -- Added check for absolute paths in fixture loading. Fixtures specified as an absolute path were being loaded multiple times. Thanks to btoll@bestweb.net for the report, fix, and catch of a duplicate ticket.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r7134 r7145  
    7272    Andrew Brehaut <http://brehaut.net/blog> 
    7373    brut.alll@gmail.com 
     74    btoll@bestweb.net 
    7475    Jonathan Buchanan <jonathan.buchanan@gmail.com> 
    7576    Can Burak Çilingir <canburak@cs.bilgi.edu.tr> 
  • django/trunk/django/core/management/commands/loaddata.py

    r7037 r7145  
    3131 
    3232        # Keep a count of the installed objects and fixtures 
    33         count = [0, 0] 
     33        fixture_count = 0 
     34        object_count = 0 
    3435        models = set() 
    3536 
     
    6667                    print "Skipping fixture '%s': %s is not a known serialization format" % (fixture_name, format) 
    6768 
    68             for fixture_dir in app_fixtures + list(settings.FIXTURE_DIRS) + ['']: 
     69            if os.path.isabs(fixture_name): 
     70                fixture_dirs = [fixture_name] 
     71            else: 
     72                fixture_dirs = app_fixtures + list(settings.FIXTURE_DIRS) + [''] 
     73 
     74            for fixture_dir in fixture_dirs: 
    6975                if verbosity > 1: 
    7076                    print "Checking %s for fixtures..." % humanize(fixture_dir) 
     
    8793                            return 
    8894                        else: 
    89                             count[1] += 1 
     95                            fixture_count += 1 
    9096                            if verbosity > 0: 
    9197                                print "Installing %s fixture '%s' from %s." % \ 
     
    94100                                objects = serializers.deserialize(format, fixture) 
    95101                                for obj in objects: 
    96                                     count[0] += 1 
     102                                    object_count += 1 
    97103                                    models.add(obj.object.__class__) 
    98104                                    obj.save() 
     
    114120                                (format, fixture_name, humanize(fixture_dir)) 
    115121 
    116         if count[0] > 0: 
     122        if object_count > 0: 
    117123            sequence_sql = connection.ops.sequence_reset_sql(self.style, models) 
    118124            if sequence_sql: 
     
    125131        transaction.leave_transaction_management() 
    126132 
    127         if count[0] == 0: 
     133        if object_count == 0: 
    128134            if verbosity >= 2: 
    129135                print "No fixtures found." 
    130136        else: 
    131137            if verbosity > 0: 
    132                 print "Installed %d object(s) from %d fixture(s)" % tuple(count) 
     138                print "Installed %d object(s) from %d fixture(s)" % (object_count, fixture_count) 
  • django/trunk/tests/regressiontests/fixtures_regress/models.py

    r6249 r7145  
    22from django.contrib.auth.models import User 
    33from django.conf import settings 
     4import os 
    45 
    56class Animal(models.Model): 
     
    2930        return unicode(name) + u' is owned by ' + unicode(self.owner) 
    3031 
     32class Absolute(models.Model): 
     33    name = models.CharField(max_length=40) 
     34 
     35    load_count = 0 
     36 
     37    def __init__(self, *args, **kwargs): 
     38        super(Absolute, self).__init__(*args, **kwargs) 
     39        Absolute.load_count += 1 
     40 
     41 
    3142__test__ = {'API_TESTS':""" 
    3243>>> from django.core import management 
     
    5061[<Stuff: None is owned by None>] 
    5162 
     63############################################### 
     64# Regression test for ticket #6436 --  
     65# os.path.join will throw away the initial parts of a path if it encounters 
     66# an absolute path. This means that if a fixture is specified as an absolute path,  
     67# we need to make sure we don't discover the absolute path in every fixture directory. 
     68 
     69>>> load_absolute_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'absolute.json') 
     70>>> management.call_command('loaddata', load_absolute_path, verbosity=0) 
     71>>> Absolute.load_count 
     721 
     73 
    5274"""}