Skip to content

Commit

Permalink
♻️Pydantic V2: Unify errors dv 2 (#6763)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg authored Nov 19, 2024
1 parent dcdc863 commit c50d79c
Show file tree
Hide file tree
Showing 26 changed files with 172 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _get_full_class_name(cls) -> str:
]
return ".".join(reversed(relevant_classes))

def error_context(self):
def error_context(self) -> dict[str, Any]:
"""Returns context in which error occurred and stored within the exception"""
return dict(**self.__dict__)

Expand Down
9 changes: 5 additions & 4 deletions packages/models-library/tests/test_rest_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ def test_ordering_query_model_class__defaults():

# checks all defaults
model = OrderQueryParamsModel()
assert model.order_by
assert isinstance(model.order_by, OrderBy) # nosec
assert model.order_by.field == "modified_at" # NOTE that this was mapped!
assert model.order_by.direction == OrderDirection.DESC
assert model.order_by is not None
assert (
model.order_by.field == "modified_at" # pylint: disable=no-member
) # NOTE that this was mapped!
assert model.order_by.direction is OrderDirection.DESC # pylint: disable=no-member

# partial defaults
model = OrderQueryParamsModel.model_validate({"order_by": {"field": "name"}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
ClusterNotFoundError,
ClustersKeeperNotAvailableError,
ComputationalRunNotFoundError,
ComputationalSchedulerError,
ConfigurationError,
PricingPlanUnitNotFoundError,
ProjectNotFoundError,
SchedulerError,
WalletNotEnoughCreditsError,
)
from ...models.comp_pipelines import CompPipelineAtDB
Expand Down Expand Up @@ -204,7 +204,9 @@ async def _get_project_node_names(
except DBProjectNotFoundError:
_logger.exception("Could not find project: %s", f"{project_id=}")
except ProjectNotFoundError as exc:
_logger.exception("Could not find parent project: %s", f"{exc.project_id=}")
_logger.exception(
"Could not find parent project: %s", exc.error_context().get("project_id")
)

return {}

Expand Down Expand Up @@ -510,7 +512,9 @@ async def get_computation(
pipeline_details=pipeline_details,
url=TypeAdapter(AnyHttpUrl).validate_python(f"{request.url}"),
stop_url=(
TypeAdapter(AnyHttpUrl).validate_python(f"{self_url}:stop?user_id={user_id}")
TypeAdapter(AnyHttpUrl).validate_python(
f"{self_url}:stop?user_id={user_id}"
)
if pipeline_state.is_running()
else None
),
Expand Down Expand Up @@ -598,7 +602,7 @@ async def stop_computation(

except ProjectNotFoundError as e:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"{e}") from e
except SchedulerError as e:
except ComputationalSchedulerError as e:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"{e}") from e


Expand Down Expand Up @@ -639,7 +643,7 @@ async def delete_computation(
# abort the pipeline first
try:
await scheduler.stop_pipeline(computation_stop.user_id, project_id)
except SchedulerError as e:
except ComputationalSchedulerError as e:
_logger.warning(
"Project %s could not be stopped properly.\n reason: %s",
project_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def create_base_app(settings: AppSettings | None = None) -> FastAPI:
for name in _NOISY_LOGGERS:
logging.getLogger(name).setLevel(quiet_level)

assert settings.SC_BOOT_MODE # nosec
app = FastAPI(
debug=settings.SC_BOOT_MODE.is_devel_mode(),
title=PROJECT_NAME,
Expand Down
Loading

0 comments on commit c50d79c

Please sign in to comment.