Author: russellm
Date: 2008-02-22 06:50:10 -0600 (Fri, 22 Feb 2008)
New Revision: 7145

Added:
   django/trunk/tests/regressiontests/fixtures_regress/fixtures/absolute.json
Modified:
   django/trunk/AUTHORS
   django/trunk/django/core/management/commands/loaddata.py
   django/trunk/tests/regressiontests/fixtures_regress/models.py
Log:
Fixed #6436 -- Added check for absolute paths in fixture loading. Fixtures 
specified as an absolute path were being loaded multiple times. Thanks to 
[EMAIL PROTECTED] for the report, fix, and catch of a duplicate ticket. 


Modified: django/trunk/AUTHORS
===================================================================
--- django/trunk/AUTHORS        2008-02-22 05:46:46 UTC (rev 7144)
+++ django/trunk/AUTHORS        2008-02-22 12:50:10 UTC (rev 7145)
@@ -71,6 +71,7 @@
     [EMAIL PROTECTED]
     Andrew Brehaut <http://brehaut.net/blog>
     [EMAIL PROTECTED]
+    [EMAIL PROTECTED]
     Jonathan Buchanan <[EMAIL PROTECTED]>
     Can Burak Çilingir <[EMAIL PROTECTED]>
     Trevor Caira <[EMAIL PROTECTED]>

Modified: django/trunk/django/core/management/commands/loaddata.py
===================================================================
--- django/trunk/django/core/management/commands/loaddata.py    2008-02-22 
05:46:46 UTC (rev 7144)
+++ django/trunk/django/core/management/commands/loaddata.py    2008-02-22 
12:50:10 UTC (rev 7145)
@@ -30,7 +30,8 @@
         show_traceback = options.get('traceback', False)
 
         # Keep a count of the installed objects and fixtures
-        count = [0, 0]
+        fixture_count = 0
+        object_count = 0
         models = set()
 
         humanize = lambda dirname: dirname and "'%s'" % dirname or 'absolute 
path'
@@ -65,7 +66,12 @@
                 else:
                     print "Skipping fixture '%s': %s is not a known 
serialization format" % (fixture_name, format)
 
-            for fixture_dir in app_fixtures + list(settings.FIXTURE_DIRS) + 
['']:
+            if os.path.isabs(fixture_name):
+                fixture_dirs = [fixture_name]
+            else:
+                fixture_dirs = app_fixtures + list(settings.FIXTURE_DIRS) + 
['']
+
+            for fixture_dir in fixture_dirs:
                 if verbosity > 1:
                     print "Checking %s for fixtures..." % humanize(fixture_dir)
 
@@ -86,14 +92,14 @@
                             transaction.leave_transaction_management()
                             return
                         else:
-                            count[1] += 1
+                            fixture_count += 1
                             if verbosity > 0:
                                 print "Installing %s fixture '%s' from %s." % \
                                     (format, fixture_name, 
humanize(fixture_dir))
                             try:
                                 objects = serializers.deserialize(format, 
fixture)
                                 for obj in objects:
-                                    count[0] += 1
+                                    object_count += 1
                                     models.add(obj.object.__class__)
                                     obj.save()
                                 label_found = True
@@ -113,7 +119,7 @@
                             print "No %s fixture '%s' in %s." % \
                                 (format, fixture_name, humanize(fixture_dir))
 
-        if count[0] > 0:
+        if object_count > 0:
             sequence_sql = connection.ops.sequence_reset_sql(self.style, 
models)
             if sequence_sql:
                 if verbosity > 1:
@@ -124,9 +130,9 @@
         transaction.commit()
         transaction.leave_transaction_management()
 
-        if count[0] == 0:
+        if object_count == 0:
             if verbosity >= 2:
                 print "No fixtures found."
         else:
             if verbosity > 0:
-                print "Installed %d object(s) from %d fixture(s)" % 
tuple(count)
+                print "Installed %d object(s) from %d fixture(s)" % 
(object_count, fixture_count)

Added: 
django/trunk/tests/regressiontests/fixtures_regress/fixtures/absolute.json
===================================================================
--- django/trunk/tests/regressiontests/fixtures_regress/fixtures/absolute.json  
                        (rev 0)
+++ django/trunk/tests/regressiontests/fixtures_regress/fixtures/absolute.json  
2008-02-22 12:50:10 UTC (rev 7145)
@@ -0,0 +1,9 @@
+[
+    {
+        "pk": "1", 
+        "model": "fixtures_regress.absolute", 
+        "fields": {
+            "name": "Load Absolute Path Test"
+        }
+    }
+]
\ No newline at end of file

Modified: django/trunk/tests/regressiontests/fixtures_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/fixtures_regress/models.py       
2008-02-22 05:46:46 UTC (rev 7144)
+++ django/trunk/tests/regressiontests/fixtures_regress/models.py       
2008-02-22 12:50:10 UTC (rev 7145)
@@ -1,6 +1,7 @@
 from django.db import models
 from django.contrib.auth.models import User
 from django.conf import settings
+import os
 
 class Animal(models.Model):
     name = models.CharField(max_length=150)
@@ -28,6 +29,16 @@
             name = None
         return unicode(name) + u' is owned by ' + unicode(self.owner)
 
+class Absolute(models.Model):
+    name = models.CharField(max_length=40)
+
+    load_count = 0
+
+    def __init__(self, *args, **kwargs):
+        super(Absolute, self).__init__(*args, **kwargs)
+        Absolute.load_count += 1
+
+
 __test__ = {'API_TESTS':"""
 >>> from django.core import management
 
@@ -49,4 +60,15 @@
 >>> Stuff.objects.all()
 [<Stuff: None is owned by None>]
 
+###############################################
+# Regression test for ticket #6436 -- 
+# os.path.join will throw away the initial parts of a path if it encounters
+# an absolute path. This means that if a fixture is specified as an absolute 
path, 
+# we need to make sure we don't discover the absolute path in every fixture 
directory.
+
+>>> load_absolute_path = os.path.join(os.path.dirname(__file__), 'fixtures', 
'absolute.json')
+>>> management.call_command('loaddata', load_absolute_path, verbosity=0)
+>>> Absolute.load_count
+1
+
 """}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to