Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️Pydantic V2: Unify errors dv 2 #6763

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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