Skip to content

Commit

Permalink
Subscription : Better handling of exception in update_subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
cserf committed Nov 6, 2023
1 parent ceedbba commit af9e29c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/rucio/core/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from sqlalchemy.sql.expression import select

from rucio.common.config import config_get_bool
from rucio.common.exception import SubscriptionNotFound, SubscriptionDuplicate, RucioException
from rucio.common.exception import SubscriptionNotFound, SubscriptionDuplicate, RucioException, UnsupportedOperation
from rucio.db.sqla import models
from rucio.db.sqla.constants import SubscriptionState
from rucio.db.sqla.session import transactional_session, stream_session, read_session
Expand Down Expand Up @@ -203,6 +203,12 @@ def update_subscription(name: str,
subscription_history.save(session=session)
except NoResultFound:
raise SubscriptionNotFound(f"Subscription for account '{account}' named '{name}' not found")
except IntegrityError as error:
if re.match('.*IntegrityError.*ORA-00001: unique constraint.*SUBSCRIPTIONS_HISTORY_PK.*violated.*', error.args[0])\
or re.match(".*IntegrityError.*UNIQUE constraint failed: subscriptions_history.id, subscriptions_history.updated_at.*", error.args[0])\
or re.match('.*IntegrityError.*duplicate key value violates unique constraint.*', error.args[0]) \
or re.match('.*UniqueViolation.*duplicate key value violates unique constraint.*', error.args[0]):
raise UnsupportedOperation(f"Subscription \'{name}\' owned by \'{account}\' cannot be updated!")


@stream_session
Expand Down
6 changes: 5 additions & 1 deletion lib/rucio/web/rest/flaskapi/v1/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from rucio.api.subscription import list_subscriptions, add_subscription, update_subscription, \
list_subscription_rule_states, get_subscription_by_id
from rucio.common.exception import InvalidObject, SubscriptionDuplicate, SubscriptionNotFound, RuleNotFound, \
AccessDenied
AccessDenied, UnsupportedOperation
from rucio.common.utils import render_json, APIEncoder
from rucio.web.rest.flaskapi.authenticated_bp import AuthenticatedBlueprint
from rucio.web.rest.flaskapi.v1.common import check_accept_header_wrapper_flask, try_stream, \
Expand Down Expand Up @@ -182,6 +182,8 @@ def put(self, account, name):
description: Invalid Auth Token
404:
description: Not found
409:
description: Unsupported Operation
"""
parameters = json_parameters()
options = param_get(parameters, 'options')
Expand All @@ -202,6 +204,8 @@ def put(self, account, name):
return generate_http_error_flask(400, InvalidObject.__name__, error.args[0])
except AccessDenied as error:
return generate_http_error_flask(401, error)
except UnsupportedOperation as error:
return generate_http_error_flask(409, error)
except SubscriptionNotFound as error:
return generate_http_error_flask(404, error)

Expand Down

0 comments on commit af9e29c

Please sign in to comment.