Skip to content

Commit

Permalink
feat: dont retry request on a validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Feb 16, 2024
1 parent 6da3bc9 commit c8a4a56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
18 changes: 13 additions & 5 deletions dm_cli/command_group/entities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from pathlib import Path

import typer
Expand All @@ -10,7 +11,8 @@
)
from typing_extensions import Annotated

from dm_cli.dmss import ApplicationException, dmss_api, dmss_exception_wrapper
from dm_cli.dmss import ApplicationException, console, dmss_api, dmss_exception_wrapper
from dm_cli.dmss_api import ApiException
from dm_cli.import_entity import import_folder_entity, import_single_entity
from dm_cli.utils.utils import destination_is_root

Expand Down Expand Up @@ -86,13 +88,19 @@ def validate_entity(
@retry(
wait=wait_random_exponential(multiplier=1, max=60),
stop=stop_after_attempt(5),
reraise=True,
retry=retry_if_not_exception_type(ApplicationException),
)
def retry_wrapper():
dmss_exception_wrapper(dmss_api.validate_existing_entity, destination)
def validation_error_wrapper():
try:
dmss_api.validate_existing_entity(destination)
except ApiException as e:
exception_body = json.loads(e.body)
if exception_body["type"] == "ValidationException":
console.print(exception_body, style="red1")
return
raise e

retry_wrapper()
dmss_exception_wrapper(validation_error_wrapper)


@entities_app.command("delete")
Expand Down
26 changes: 15 additions & 11 deletions dm_cli/utils/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ def resolve_reference(
) -> str:
destination = destination.rstrip("/")
root_package = file_path.split("/", 1)[0] if file_path else ""
if "://" in reference or reference == "_default_" or reference[0] == "^" or reference[0] == "~":
return reference
if ":" in reference:
return resolve_dependency(reference, dependencies)
if reference[0] == ".":
normalized_dotted_ref: str = normpath(f"{file_path}/{reference}")
return f"dmss://{destination}/{normalized_dotted_ref}"
if reference[0] == "/":
data_source = destination.split("/")[0]
return f"dmss://{data_source}{reference}"
return f"dmss://{destination}/{root_package}/{reference}"
try:
if "://" in reference or reference == "_default_" or reference[0] == "^" or reference[0] == "~":
return reference
if ":" in reference:
return resolve_dependency(reference, dependencies)
if reference[0] == ".":
normalized_dotted_ref: str = normpath(f"{file_path}/{reference}")
return f"dmss://{destination}/{normalized_dotted_ref}"
if reference[0] == "/":
data_source = destination.split("/")[0]
return f"dmss://{data_source}{reference}"
return f"dmss://{destination}/{root_package}/{reference}"
except ApplicationException as ex:
ex.debug = f"File: {file_path}, Destination: {destination}, Root: {root_package}"
raise ex


def resolve_storage_reference(address: str, source_path: Path):
Expand Down

0 comments on commit c8a4a56

Please sign in to comment.