Commits

Luke Plant  committed 25c6529

- Fixed name error
- Added logic so that duplicate errors wouldn't be saved for the same page

  • Participants
  • Parent commits 1b9cba2

Comments (0)

Files changed (1)

File django/validator/models.py

         from django.conf import settings
         try:
             VALIDATOR_APP_IGNORE_PATHS = settings.VALIDATOR_APP_IGNORE_PATHS
-        except Attribute:
+        except AttributeError:
             VALIDATOR_APP_IGNORE_PATHS = ()
                   
         import tempfile
         (child_stdin, child_output) = os.popen4(validator + ' ' + tmpfilepath)
         errors = child_output.read()
         
+        # Normalise output so that we can eliminate duplicate errors
+        errors = errors.replace(tmpfilepath, '[tmpfilepath]')
+        
         # clean up
         child_stdin.close()
         child_output.close()
         os.unlink(tmpfilepath)
+
+        # Only save if there was an error, and there isn't already
+        # a failure saved at the same URL with identical errors.
+        # (this isn't perfectly watertight -- you could by chance be
+        # generating identical errors with different query strings or
+        # POST data, but it's unlikely).
         
-        if len(errors) > 0:
+        if len(errors) > 0 and \
+               ValidationFailure.objects.filter(errors=errors,
+                                                path=request.path).count() == 0:
             failure = ValidationFailure(errors=errors)
             failure.path = request.path
             qs = request.META.get('QUERY_STRING','')