mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
chore(dao/command): Add transaction decorator to try to enforce "unit of work" (#24969)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from functools import partial
|
||||
from typing import Any
|
||||
|
||||
from flask_appbuilder.models.sqla import Model
|
||||
@@ -27,7 +28,7 @@ from superset.commands.annotation_layer.exceptions import (
|
||||
)
|
||||
from superset.commands.base import BaseCommand
|
||||
from superset.daos.annotation_layer import AnnotationLayerDAO
|
||||
from superset.daos.exceptions import DAOCreateFailedError
|
||||
from superset.utils.decorators import on_error, transaction
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -36,13 +37,10 @@ class CreateAnnotationLayerCommand(BaseCommand):
|
||||
def __init__(self, data: dict[str, Any]):
|
||||
self._properties = data.copy()
|
||||
|
||||
@transaction(on_error=partial(on_error, reraise=AnnotationLayerCreateFailedError))
|
||||
def run(self) -> Model:
|
||||
self.validate()
|
||||
try:
|
||||
return AnnotationLayerDAO.create(attributes=self._properties)
|
||||
except DAOCreateFailedError as ex:
|
||||
logger.exception(ex.exception)
|
||||
raise AnnotationLayerCreateFailedError() from ex
|
||||
return AnnotationLayerDAO.create(attributes=self._properties)
|
||||
|
||||
def validate(self) -> None:
|
||||
exceptions: list[ValidationError] = []
|
||||
|
||||
Reference in New Issue
Block a user