Commit ba070c39 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Remove custom commit_on_success decorator

Prior to 1.3, django wouldn't set the transaction dirty upon a DB
exception and thus wouldn't trigger a rollback, resulting in a dangling
aborted DB exception. See https://code.djangoproject.com/ticket/9964

Since this is now fixed, there is no need for our custom transaction
management.
parent 09a7d63b
...@@ -36,8 +36,8 @@ from django.utils import simplejson as json ...@@ -36,8 +36,8 @@ from django.utils import simplejson as json
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse from django.http import HttpResponse
from django.db.models import Q from django.db.models import Q
from django.db import transaction
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.api.util import json_response from astakos.api.util import json_response
from snf_django.lib import api from snf_django.lib import api
...@@ -271,7 +271,7 @@ def projects(request): ...@@ -271,7 +271,7 @@ def projects(request):
@api.api_method(http_method="GET", token_required=True, user_required=False) @api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def get_projects(request): def get_projects(request):
user = request.user user = request.user
input_data = read_json_body(request, default={}) input_data = read_json_body(request, default={})
...@@ -299,7 +299,7 @@ def _get_projects(query, request_user=None): ...@@ -299,7 +299,7 @@ def _get_projects(query, request_user=None):
@api.api_method(http_method="POST", token_required=True, user_required=False) @api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def create_project(request): def create_project(request):
user = request.user user = request.user
data = request.body data = request.body
...@@ -319,7 +319,7 @@ def project(request, project_id): ...@@ -319,7 +319,7 @@ def project(request, project_id):
@api.api_method(http_method="GET", token_required=True, user_required=False) @api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def get_project(request, project_id): def get_project(request, project_id):
user = request.user user = request.user
with ExceptionHandler(): with ExceptionHandler():
...@@ -337,7 +337,7 @@ def _get_project(project_id, request_user=None): ...@@ -337,7 +337,7 @@ def _get_project(project_id, request_user=None):
@api.api_method(http_method="POST", token_required=True, user_required=False) @api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def modify_project(request, project_id): def modify_project(request, project_id):
user = request.user user = request.user
data = request.body data = request.body
...@@ -466,7 +466,7 @@ PROJECT_ACTION = { ...@@ -466,7 +466,7 @@ PROJECT_ACTION = {
@csrf_exempt @csrf_exempt
@api.api_method(http_method="POST", token_required=True, user_required=False) @api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def project_action(request, project_id): def project_action(request, project_id):
user = request.user user = request.user
data = request.body data = request.body
...@@ -497,7 +497,7 @@ def make_application_query(input_data): ...@@ -497,7 +497,7 @@ def make_application_query(input_data):
@api.api_method(http_method="GET", token_required=True, user_required=False) @api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def get_applications(request): def get_applications(request):
user = request.user user = request.user
input_data = read_json_body(request, default={}) input_data = read_json_body(request, default={})
...@@ -520,7 +520,7 @@ def _get_applications(query, request_user=None): ...@@ -520,7 +520,7 @@ def _get_applications(query, request_user=None):
@csrf_exempt @csrf_exempt
@api.api_method(http_method="GET", token_required=True, user_required=False) @api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def application(request, app_id): def application(request, app_id):
user = request.user user = request.user
with ExceptionHandler(): with ExceptionHandler():
...@@ -547,7 +547,7 @@ APPLICATION_ACTION = { ...@@ -547,7 +547,7 @@ APPLICATION_ACTION = {
@csrf_exempt @csrf_exempt
@api.api_method(http_method="POST", token_required=True, user_required=False) @api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def application_action(request, app_id): def application_action(request, app_id):
user = request.user user = request.user
data = request.body data = request.body
...@@ -581,7 +581,7 @@ def make_membership_query(input_data): ...@@ -581,7 +581,7 @@ def make_membership_query(input_data):
@api.api_method(http_method="GET", token_required=True, user_required=False) @api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def get_memberships(request): def get_memberships(request):
user = request.user user = request.user
input_data = read_json_body(request, default={}) input_data = read_json_body(request, default={})
...@@ -631,7 +631,7 @@ MEMBERSHIPS_ACTION = { ...@@ -631,7 +631,7 @@ MEMBERSHIPS_ACTION = {
@api.api_method(http_method="POST", token_required=True, user_required=False) @api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def post_memberships(request): def post_memberships(request):
user = request.user user = request.user
data = request.body data = request.body
...@@ -642,7 +642,7 @@ def post_memberships(request): ...@@ -642,7 +642,7 @@ def post_memberships(request):
@api.api_method(http_method="GET", token_required=True, user_required=False) @api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def membership(request, memb_id): def membership(request, memb_id):
user = request.user user = request.user
with ExceptionHandler(): with ExceptionHandler():
...@@ -669,7 +669,7 @@ MEMBERSHIP_ACTION = { ...@@ -669,7 +669,7 @@ MEMBERSHIP_ACTION = {
@csrf_exempt @csrf_exempt
@api.api_method(http_method="POST", token_required=True, user_required=False) @api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token @user_from_token
@commit_on_success_strict() @transaction.commit_on_success
def membership_action(request, memb_id): def membership_action(request, memb_id):
user = request.user user = request.user
input_data = read_json_body(request, default={}) input_data = read_json_body(request, default={})
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
from django.utils import simplejson as json from django.utils import simplejson as json
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse from django.http import HttpResponse
from django.db import transaction
from snf_django.lib.db.transaction import commit_on_success_strict
from snf_django.lib import api from snf_django.lib import api
from snf_django.lib.api.faults import BadRequest, ItemNotFound from snf_django.lib.api.faults import BadRequest, ItemNotFound
...@@ -175,7 +174,7 @@ def issue_commission(request): ...@@ -175,7 +174,7 @@ def issue_commission(request):
return json_response(data, status_code=status_code) return json_response(data, status_code=status_code)
@commit_on_success_strict() @transaction.commit_on_success
def _issue_commission(clientkey, provisions, name, force, accept): def _issue_commission(clientkey, provisions, name, force, accept):
serial = qh.issue_commission(clientkey=clientkey, serial = qh.issue_commission(clientkey=clientkey,
provisions=provisions, provisions=provisions,
...@@ -204,7 +203,7 @@ def conflictingCF(serial): ...@@ -204,7 +203,7 @@ def conflictingCF(serial):
@csrf_exempt @csrf_exempt
@api.api_method(http_method='POST', token_required=True, user_required=False) @api.api_method(http_method='POST', token_required=True, user_required=False)
@component_from_token @component_from_token
@commit_on_success_strict() @transaction.commit_on_success
def resolve_pending_commissions(request): def resolve_pending_commissions(request):
data = request.body data = request.body
try: try:
...@@ -260,7 +259,7 @@ def get_commission(request, serial): ...@@ -260,7 +259,7 @@ def get_commission(request, serial):
@csrf_exempt @csrf_exempt
@api.api_method(http_method='POST', token_required=True, user_required=False) @api.api_method(http_method='POST', token_required=True, user_required=False)
@component_from_token @component_from_token
@commit_on_success_strict() @transaction.commit_on_success
def serial_action(request, serial): def serial_action(request, serial):
data = request.body data = request.body
try: try:
......
...@@ -32,15 +32,15 @@ ...@@ -32,15 +32,15 @@
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from astakos.im.models import Component from astakos.im.models import Component
from snf_django.lib.db.transaction import commit_on_success_strict
class Command(BaseCommand): class Command(BaseCommand):
args = "<component ID or name>" args = "<component ID or name>"
help = "Remove a component along with its registered services" help = "Remove a component along with its registered services"
@commit_on_success_strict() @transaction.commit_on_success
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) != 1: if len(args) != 1:
raise CommandError("Please provide a component ID or name") raise CommandError("Please provide a component ID or name")
......
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
from optparse import make_option from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from astakos.im.functions import (terminate, suspend, unsuspend, from astakos.im.functions import (terminate, suspend, unsuspend,
reinstate, check_expiration, reinstate, check_expiration,
approve_application, deny_application) approve_application, deny_application)
from snf_django.lib.db.transaction import commit_on_success_strict
class Command(BaseCommand): class Command(BaseCommand):
...@@ -86,7 +86,7 @@ class Command(BaseCommand): ...@@ -86,7 +86,7 @@ class Command(BaseCommand):
"e.g. when denying a project")), "e.g. when denying a project")),
) )
@commit_on_success_strict() @transaction.commit_on_success
def handle(self, *args, **options): def handle(self, *args, **options):
message = options['message'] message = options['message']
......
...@@ -33,13 +33,13 @@ ...@@ -33,13 +33,13 @@
from optparse import make_option from optparse import make_option
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.db import transaction
from astakos.im.models import AstakosUser from astakos.im.models import AstakosUser
from astakos.im.quotas import ( from astakos.im.quotas import (
qh_sync_users_diffs, list_user_quotas, add_base_quota) qh_sync_users_diffs, list_user_quotas, add_base_quota)
from astakos.im.functions import get_user_by_uuid from astakos.im.functions import get_user_by_uuid
from astakos.im.management.commands._common import is_uuid, is_email from astakos.im.management.commands._common import is_uuid, is_email
from snf_django.lib.db.transaction import commit_on_success_strict
from snf_django.management.commands import SynnefoCommand from snf_django.management.commands import SynnefoCommand
from snf_django.management import utils from snf_django.management import utils
from ._common import show_quotas, style_options, check_style, units from ._common import show_quotas, style_options, check_style, units
...@@ -87,7 +87,7 @@ class Command(SynnefoCommand): ...@@ -87,7 +87,7 @@ class Command(SynnefoCommand):
), ),
) )
@commit_on_success_strict() @transaction.commit_on_success
def handle(self, *args, **options): def handle(self, *args, **options):
sync = options['sync'] sync = options['sync']
verify = options['verify'] verify = options['verify']
......
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from snf_django.management.utils import pprint_table from snf_django.management.utils import pprint_table
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.im.models import Component, AstakosUser from astakos.im.models import Component, AstakosUser
from astakos.im.quotas import service_get_quotas, SYSTEM from astakos.im.quotas import service_get_quotas, SYSTEM
from astakos.im.functions import count_pending_app from astakos.im.functions import count_pending_app
...@@ -67,7 +67,7 @@ class Command(BaseCommand): ...@@ -67,7 +67,7 @@ class Command(BaseCommand):
" the quota, independently of their value.") " the quota, independently of their value.")
) )
@commit_on_success_strict() @transaction.commit_on_success
def handle(self, *args, **options): def handle(self, *args, **options):
write = self.stdout.write write = self.stdout.write
force = options['force'] force = options['force']
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
from optparse import make_option from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.utils import simplejson as json from django.utils import simplejson as json
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.im.register import add_resource, RegisterException from astakos.im.register import add_resource, RegisterException
from ._common import read_from_file from ._common import read_from_file
...@@ -69,7 +69,7 @@ class Command(BaseCommand): ...@@ -69,7 +69,7 @@ class Command(BaseCommand):
raise CommandError(m) raise CommandError(m)
self.add_resources(data) self.add_resources(data)
@commit_on_success_strict() @transaction.commit_on_success
def add_resources(self, resources): def add_resources(self, resources):
output = [] output = []
for resource in resources: for resource in resources:
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
from optparse import make_option from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.utils import simplejson as json from django.utils import simplejson as json
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.im.register import add_service, add_resource, RegisterException from astakos.im.register import add_service, add_resource, RegisterException
from astakos.im.models import Component from astakos.im.models import Component
from ._common import read_from_file from ._common import read_from_file
...@@ -52,7 +52,7 @@ class Command(BaseCommand): ...@@ -52,7 +52,7 @@ class Command(BaseCommand):
help="Load service definitions from a json file"), help="Load service definitions from a json file"),
) )
@commit_on_success_strict() @transaction.commit_on_success
def handle(self, *args, **options): def handle(self, *args, **options):
json_file = options['json'] json_file = options['json']
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
from optparse import make_option from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.core.validators import validate_email from django.core.validators import validate_email
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from snf_django.lib.db import transaction
from astakos.im.models import AstakosUser from astakos.im.models import AstakosUser
...@@ -67,7 +67,7 @@ class Command(BaseCommand): ...@@ -67,7 +67,7 @@ class Command(BaseCommand):
help="Add user permission (may be used multiple times)") help="Add user permission (may be used multiple times)")
) )
@transaction.commit_on_success_strict() @transaction.commit_on_success
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) != 3: if len(args) != 3:
raise CommandError("Invalid number of arguments") raise CommandError("Invalid number of arguments")
......
...@@ -36,6 +36,7 @@ import string ...@@ -36,6 +36,7 @@ import string
from optparse import make_option from optparse import make_option
from django.core import management from django.core import management
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
...@@ -47,7 +48,6 @@ from astakos.im import quotas ...@@ -47,7 +48,6 @@ from astakos.im import quotas
from astakos.im import activation_backends from astakos.im import activation_backends
from ._common import (remove_user_permission, add_user_permission, is_uuid, from ._common import (remove_user_permission, add_user_permission, is_uuid,
show_resource_value) show_resource_value)
from snf_django.lib.db.transaction import commit_on_success_strict
activation_backend = activation_backends.get_backend() activation_backend = activation_backends.get_backend()
...@@ -151,7 +151,7 @@ class Command(BaseCommand): ...@@ -151,7 +151,7 @@ class Command(BaseCommand):
help="Delete user"), help="Delete user"),
) )
@commit_on_success_strict() @transaction.commit_on_success
def handle(self, *args, **options): def handle(self, *args, **options):
if len(args) != 1: if len(args) != 1:
raise CommandError("Please provide a user ID") raise CommandError("Please provide a user ID")
......
...@@ -48,8 +48,7 @@ from django.utils.translation import ugettext as _ ...@@ -48,8 +48,7 @@ from django.utils.translation import ugettext as _
from django.views.generic.list_detail import object_list, object_detail from django.views.generic.list_detail import object_list, object_detail
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.views.decorators.http import require_http_methods from django.views.decorators.http import require_http_methods
from django.db import transaction
from snf_django.lib.db.transaction import commit_on_success_strict
import astakos.im.messages as astakos_messages import astakos.im.messages as astakos_messages
...@@ -123,7 +122,7 @@ def project_add(request): ...@@ -123,7 +122,7 @@ def project_add(request):
return redirect(next) return redirect(next)
@commit_on_success_strict() @transaction.commit_on_success
def create_app_object(request, extra_context=None): def create_app_object(request, extra_context=None):
try: try:
summary = 'im/projects/projectapplication_form_summary.html' summary = 'im/projects/projectapplication_form_summary.html'
...@@ -191,7 +190,7 @@ def project_app_cancel(request, application_id): ...@@ -191,7 +190,7 @@ def project_app_cancel(request, application_id):
return redirect(next) return redirect(next)
@commit_on_success_strict() @transaction.commit_on_success
def _project_app_cancel(request, application_id): def _project_app_cancel(request, application_id):
chain_id = None chain_id = None
try: try:
...@@ -264,7 +263,7 @@ def project_modify(request, application_id): ...@@ -264,7 +263,7 @@ def project_modify(request, application_id):
return redirect(next) return redirect(next)
@commit_on_success_strict() @transaction.commit_on_success
def update_app_object(request, object_id, extra_context=None): def update_app_object(request, object_id, extra_context=None):
try: try:
summary = 'im/projects/projectapplication_form_summary.html' summary = 'im/projects/projectapplication_form_summary.html'
...@@ -296,7 +295,7 @@ def project_detail(request, chain_id): ...@@ -296,7 +295,7 @@ def project_detail(request, chain_id):
return common_detail(request, chain_id) return common_detail(request, chain_id)
@commit_on_success_strict() @transaction.commit_on_success
def addmembers(request, chain_id, addmembers_form): def addmembers(request, chain_id, addmembers_form):
if addmembers_form.is_valid(): if addmembers_form.is_valid():
try: try:
...@@ -476,7 +475,7 @@ def project_join(request, chain_id): ...@@ -476,7 +475,7 @@ def project_join(request, chain_id):
return redirect(next) return redirect(next)
@commit_on_success_strict() @transaction.commit_on_success
def _project_join(request, chain_id): def _project_join(request, chain_id):
try: try:
chain_id = int(chain_id) chain_id = int(chain_id)
...@@ -505,7 +504,7 @@ def project_leave(request, memb_id): ...@@ -505,7 +504,7 @@ def project_leave(request, memb_id):
return redirect(next) return redirect(next)
@commit_on_success_strict() @transaction.commit_on_success
def _project_leave(request, memb_id): def _project_leave(request, memb_id):
try: try:
memb_id = int(memb_id) memb_id = int(memb_id)
...@@ -534,7 +533,7 @@ def project_cancel_member(request, memb_id): ...@@ -534,7 +533,7 @@ def project_cancel_member(request, memb_id):
return redirect(next) return redirect(next)
@commit_on_success_strict() @transaction.commit_on_success
def _project_cancel_member(request, memb_id): def _project_cancel_member(request, memb_id):
try: try:
cancel_membership(memb_id, request.user) cancel_membership(memb_id, request.user)
...@@ -555,7 +554,7 @@ def project_accept_member(request, memb_id): ...@@ -555,7 +554,7 @@ def project_accept_member(request, memb_id):
return redirect_back(request, 'project_list') return redirect_back(request, 'project_list')
@commit_on_success_strict() @transaction.commit_on_success
def _project_accept_member(request, memb_id): def _project_accept_member(request, memb_id):
try: