Index: tests/regressiontests/directory_creation/__init__.py
===================================================================
--- tests/regressiontests/directory_creation/__init__.py	(revision 0)
+++ tests/regressiontests/directory_creation/__init__.py	(revision 0)
@@ -0,0 +1 @@
+ 
Index: tests/regressiontests/directory_creation/tests.py
===================================================================
--- tests/regressiontests/directory_creation/tests.py	(revision 0)
+++ tests/regressiontests/directory_creation/tests.py	(revision 0)
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+"""
+Tests for directory creation via _save_FIELD_file (ticket #6450)
+"""
+import shutil
+import unittest
+import os
+import errno
+
+from regressiontests.directory_creation.models import Foo, UPLOAD_ROOT, \
+    UPLOAD_TO
+
+
+class TestDirectoryCreation(unittest.TestCase):
+
+    def setUp(self):
+        self.obj = Foo()
+        if not os.path.isdir(UPLOAD_ROOT):
+            os.makedirs(UPLOAD_ROOT)
+
+    def tearDown(self):
+        os.chmod(UPLOAD_ROOT, 0700)
+        shutil.rmtree(UPLOAD_ROOT)
+
+    def test_readonly_root(self):
+        """Test that permission errors are not swallowed"""
+        os.chmod(UPLOAD_ROOT, 0500)
+        try:
+            self.obj.save_f_file('foo.txt', 'x')
+        except OSError, err:
+            self.assertEquals(err.errno, errno.EACCES)
+        except:
+            self.fail("OSError [Errno %s] not raised" % errno.EACCES)
+
+    def test_not_a_directory(self):
+        """Test that the expected IOError is raised"""
+        # create a file with the upload directory name:
+        fd = open(UPLOAD_TO, 'w')
+        fd.close()
+        try:
+            self.obj.save_f_file('foo.txt', 'x')
+        except IOError, err:
+            # The test needs to be done on a specific string as IOError
+            # is raised even without the patch (just not early enough)
+            self.assertEquals(err.args[0], 
+                              "%s exists and is not a directory" % UPLOAD_TO)
+        except:
+            self.fail("IOError not raised")
Index: tests/regressiontests/directory_creation/models.py
===================================================================
--- tests/regressiontests/directory_creation/models.py	(revision 0)
+++ tests/regressiontests/directory_creation/models.py	(revision 0)
@@ -0,0 +1,11 @@
+import tempfile
+import os
+from django.db import models
+
+
+UPLOAD_ROOT = tempfile.mkdtemp()
+UPLOAD_TO = os.path.join(UPLOAD_ROOT, 'foo_upload')
+
+
+class Foo(models.Model):
+    f = models.FileField(upload_to=UPLOAD_TO)
