Browse Source

Upgrade Django to 1.6

David Cramer 10 years ago
parent
commit
da3aaab015

+ 0 - 3
conftest.py

@@ -28,9 +28,6 @@ def pytest_configure(config):
             'ENGINE': 'django.db.backends.postgresql_psycopg2',
             'USER': 'postgres',
             'NAME': 'sentry',
-            'OPTIONS': {
-                'autocommit': True,
-            }
         })
     elif test_db == 'sqlite':
         settings.DATABASES['default'].update({

+ 0 - 3
docs/quickstart/index.rst

@@ -145,9 +145,6 @@ is not a fully supported database and should not be used in production**.
             'PASSWORD': '',
             'HOST': '',
             'PORT': '',
-            'OPTIONS': {
-                'autocommit': True,
-            }
         }
     }
 

+ 1 - 1
setup.cfg

@@ -6,7 +6,7 @@ norecursedirs=bin dist docs	htmlcov script hooks node_modules .* {args}
 [flake8]
 ignore = F999,E501,E128,E124,F841
 max-line-length = 100
-exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs
+exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs/*
 
 [wheel]
 universal = 1

+ 1 - 1
setup.py

@@ -70,7 +70,7 @@ install_requires = [
     'BeautifulSoup>=3.2.1,<3.3.0',
     'celery>=3.0.15,<3.1.0',
     'cssutils>=0.9.9,<0.10.0',
-    'Django>=1.5.8,<1.6',
+    'Django>=1.6.0,<1.7',
     'django-bitfield>=1.7.0,<1.8.0',
     'django-celery>=3.0.11,<3.1.0',
     'django-crispy-forms>=1.2.3,<1.3.0',

+ 1 - 1
src/sentry/admin.py

@@ -164,7 +164,7 @@ class UserAdmin(admin.ModelAdmin):
 
     @sensitive_post_parameters_m
     @csrf_protect_m
-    @transaction.commit_on_success
+    @transaction.atomic
     def add_view(self, request, form_url='', extra_context=None):
         # It's an error for a user to have add permission but NOT change
         # permission for users. If we allowed such users to add users, they

+ 3 - 0
src/sentry/conf/server.py

@@ -56,6 +56,9 @@ DATABASES = {
     }
 }
 
+ATOMIC_REQUESTS = False
+AUTOCOMMIT = True
+
 if 'DATABASE_URL' in os.environ:
     url = urlparse.urlparse(os.environ['DATABASE_URL'])
 

+ 5 - 5
src/sentry/db/models/query.py

@@ -1,6 +1,6 @@
 """
-sentry.db.query
-~~~~~~~~~~~~~~~
+sentry.db.models.query
+~~~~~~~~~~~~~~~~~~~~~~
 
 :copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
 :license: BSD, see LICENSE for more details.
@@ -8,7 +8,7 @@ sentry.db.query
 
 from __future__ import absolute_import
 
-from django.db import router, transaction, IntegrityError
+from django.db import IntegrityError, router, transaction
 from django.db.models.expressions import ExpressionNode
 from django.db.models.signals import post_save
 
@@ -77,9 +77,9 @@ def create_or_update(model, using=None, **kwargs):
         else:
             create_kwargs[k] = v
     try:
-        return objects.create(**create_kwargs), True
+        with transaction.atomic():
+            return objects.create(**create_kwargs), True
     except IntegrityError:
-        transaction.rollback_unless_managed(using=using)
         affected = objects.filter(**kwargs).update(**defaults)
 
     return affected, False

+ 11 - 16
src/sentry/event_manager.py

@@ -223,7 +223,7 @@ class EventManager(object):
         return data
 
     @suppress_exceptions
-    @transaction.commit_on_success
+    @transaction.atomic
     def save(self, project, raw=False):
         # TODO: culprit should default to "most recent" frame in stacktraces when
         # it's not provided.
@@ -317,23 +317,18 @@ class EventManager(object):
 
         # save the event unless its been sampled
         if not is_sample:
-            sid = transaction.savepoint(using=using)
             try:
-                event.save()
+                with transaction.atomic():
+                    event.save()
             except IntegrityError:
-                transaction.savepoint_rollback(sid, using=using)
                 return event
-            transaction.savepoint_commit(sid, using=using)
 
-        sid = transaction.savepoint(using=using)
         try:
-            EventMapping.objects.create(
-                project=project, group=group, event_id=event_id)
+            with transaction.atomic():
+                EventMapping.objects.create(
+                    project=project, group=group, event_id=event_id)
         except IntegrityError:
-            transaction.savepoint_rollback(sid, using=using)
             return event
-        transaction.savepoint_commit(sid, using=using)
-        transaction.commit_unless_managed(using=using)
 
         if not raw:
             post_process_group.delay(
@@ -446,10 +441,6 @@ class EventManager(object):
         else:
             is_regression = False
 
-            # We need to commit because the queue can run too fast and hit
-            # an issue with the group not existing before the buffers run
-            transaction.commit_unless_managed(using=group._state.db)
-
         # Determine if we've sampled enough data to store this event
         if is_new:
             is_sample = False
@@ -458,6 +449,10 @@ class EventManager(object):
         else:
             is_sample = True
 
+        # We need to commit because the queue can run too fast and hit
+        # an issue with the group not existing before the buffers run
+        transaction.commit(using=group._state.db)
+
         # Rounded down to the nearest interval
         safe_execute(Group.objects.add_tags, group, tags)
 
@@ -491,7 +486,7 @@ class EventManager(object):
                 active_at__gte=date - timedelta(seconds=5),
             ).update(active_at=date, status=GroupStatus.UNRESOLVED))
 
-            transaction.commit_unless_managed(using=group._state.db)
+            transaction.commit(using=group._state.db)
 
             group.active_at = date
             group.status = GroupStatus.UNRESOLVED

+ 4 - 8
src/sentry/utils/query.py

@@ -9,7 +9,7 @@ from __future__ import absolute_import
 
 import progressbar
 
-from django.db import transaction, IntegrityError
+from django.db import IntegrityError, transaction
 from django.db.models import ForeignKey
 from django.db.models.deletion import Collector
 from django.db.models.signals import pre_delete, pre_save, post_save, post_delete
@@ -254,16 +254,12 @@ def merge_into(self, other, callback=lambda x: x, using='default'):
             if send_signals:
                 pre_save.send(created=True, **signal_kwargs)
 
-            sid = transaction.savepoint(using=using)
-
             try:
-                model.objects.filter(pk=obj.pk).update(**update_kwargs)
+                with transaction.atomic():
+                    model.objects.using(using).filter(pk=obj.pk).update(**update_kwargs)
             except IntegrityError:
                 # duplicate key exists, destroy the relations
-                transaction.savepoint_rollback(sid, using=using)
-                model.objects.filter(pk=obj.pk).delete()
-            else:
-                transaction.savepoint_commit(sid, using=using)
+                model.objects.using(using).filter(pk=obj.pk).delete()
 
             if send_signals:
                 post_save.send(created=True, **signal_kwargs)

+ 0 - 5
src/sentry/utils/runner.py

@@ -43,11 +43,6 @@ DATABASES = {
         'PASSWORD': '',
         'HOST': '',
         'PORT': '',
-
-        # If you're using Postgres, we recommend turning on autocommit
-        # 'OPTIONS': {
-        #     'autocommit': True,
-        # }
     }
 }
 

Some files were not shown because too many files changed in this diff