Skip to content
Snippets Groups Projects
Unverified Commit 55f33b1b authored by Katleho Madisa's avatar Katleho Madisa
Browse files

SAR-149 Validating the params arguments.

parent 5a8e8efb
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ import json ...@@ -5,7 +5,7 @@ import json
import logging import logging
import os import os
from typing import Text from typing import Mapping, Text
from ska.skuid.client import SkuidClient from ska.skuid.client import SkuidClient
...@@ -64,15 +64,15 @@ class Transaction: ...@@ -64,15 +64,15 @@ class Transaction:
transaction_id: str = "", transaction_id: str = "",
transaction_id_key: str = "transaction_id", transaction_id_key: str = "transaction_id",
): ):
if not isinstance(params, Mapping):
raise TransactionParamsError("params must be dict-like (Mapping)")
# Get the root logger # Get the root logger
self.logger = logging.getLogger() self.logger = logging.getLogger()
self._name = name self._name = name
self._params = params self._params = params
self._transaction_id_key = transaction_id_key self._transaction_id_key = transaction_id_key
self._transaction_id = ( self._transaction_id = transaction_id if self._is_valid_id(transaction_id) else ""
transaction_id if self._is_valid_id(transaction_id) else ""
)
if not self._transaction_id: if not self._transaction_id:
self._transaction_id = self._get_from_params_or_generate_new_id() self._transaction_id = self._get_from_params_or_generate_new_id()
...@@ -94,9 +94,7 @@ class Transaction: ...@@ -94,9 +94,7 @@ class Transaction:
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type: if exc_type:
self.logger.exception( self.logger.exception(f"Transaction[{self._transaction_id}]: Exception[{self._name}]")
f"Transaction[{self._transaction_id}]: Exception[{self._name}]"
)
self.logger.info(f"Transaction[{self._transaction_id}]: Exit[{self._name}]") self.logger.info(f"Transaction[{self._transaction_id}]: Exit[{self._name}]")
...@@ -161,3 +159,7 @@ class TransactionIdGenerator: ...@@ -161,3 +159,7 @@ class TransactionIdGenerator:
def next(self): def next(self):
return self._get_id() return self._get_id()
class TransactionParamsError(TypeError):
"""Invalid data type for transaction parameters."""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment