Commits

Daniel LaMotte  committed a137a37

middleware: rolling back when hitting database issues during visitor.save()

  • Participants
  • Parent commits b8bf53b

Comments (0)

Files changed (1)

File tracking/middleware.py

 from django.conf import settings
 from django.contrib.auth.models import AnonymousUser
 from django.core.cache import cache
+from django.db import transaction
 from django.db.utils import DatabaseError
 from django.http import Http404
 from tracking import utils
         visitor.page_views += 1
         visitor.last_update = now
         try:
+            sid = transaction.savepoint()
             visitor.save()
+            transaction.savepoint_commit(sid)
         except DatabaseError:
+            transaction.savepoint_rollback(sid)
             log.error('There was a problem saving visitor information:\n%s\n\n%s' % (traceback.format_exc(), locals()))
 
 class VisitorCleanUpMiddleware: