Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Jul 4, 2023
1 parent 691ad0c commit 623c1b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#


class ProjectNotFound(Exception):
class ProjectNotFoundError(Exception):
code = "projects.not_found"


class BaseProjectJobMetadataError(Exception):
...


class ProjectJobMetadataNotFound(BaseProjectJobMetadataError):
class ProjectJobMetadataNotFoundError(BaseProjectJobMetadataError):
code = "projects.job_metadata.not_found"


Expand Down Expand Up @@ -67,10 +67,10 @@ async def create_solver_job(
job_metadata: dict[str, Any] | None = None,
) -> ProjectJobMetadata:

values: dict[str, Any] = dict(
project_uuid=project_uuid,
parent_name=self._get_parent_name(service_key, service_version),
)
values: dict[str, Any] = {
"project_uuid": project_uuid,
"parent_name": self._get_parent_name(service_key, service_version),
}
if job_metadata:
values["job_metadata"] = job_metadata

Expand All @@ -86,9 +86,8 @@ async def create_solver_job(
return ProjectJobMetadata.from_row(row)

except ForeignKeyViolation as exc:
raise ProjectNotFound(
f"Cannot create metadata without a valid project {project_uuid=}"
) from exc
msg = f"Cannot create metadata without a valid project {project_uuid=}"
raise ProjectNotFoundError(msg) from exc

async def list_solver_jobs(
self,
Expand Down Expand Up @@ -122,7 +121,7 @@ async def get(
result: ResultProxy = await connection.execute(get_stmt)
if row := await result.first():
return ProjectJobMetadata.from_row(row)
raise ProjectJobMetadataNotFound
raise ProjectJobMetadataNotFoundError

async def update(
self,
Expand All @@ -141,14 +140,13 @@ async def update(
result = await connection.execute(update_stmt)
if row := await result.first():
return ProjectJobMetadata.from_row(row)
raise ProjectJobMetadataNotFound
raise ProjectJobMetadataNotFoundError

async def delete(self, connection: SAConnection, project_uuid: uuid.UUID) -> None:
delete_stmt = sa.delete(projects_jobs_metadata).where(
projects_jobs_metadata.c.project_uuid == f"{project_uuid}"
)
result = await connection.execute(delete_stmt)
if result.rowcount:
raise ProjectJobMetadataNotFound(
f"Could not delete non-existing metadata of {project_uuid=}"
)
msg = f"Could not delete non-existing metadata of project_uuid={project_uuid!r}"
raise ProjectJobMetadataNotFoundError(msg)
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from simcore_postgres_database.utils_projects_metadata import (
ProjectJobMetadata,
ProjectJobMetadataNotFound,
ProjectJobMetadataNotFoundError,
ProjectJobMetadataRepo,
ProjectNotFound,
ProjectNotFoundError,
)

assert ProjectJobMetadata # nosec
assert ProjectJobMetadataRepo # nosec
assert ProjectJobMetadataNotFound # nosec
assert ProjectNotFound
assert ProjectJobMetadataNotFoundError # nosec
assert ProjectNotFoundError


__all__: tuple[str, ...] = (
"ProjectJobMetadata",
"ProjectJobMetadataRepo",
"ProjectJobMetadataNotFound",
"ProjectJobMetadataNotFoundError",
)

0 comments on commit 623c1b0

Please sign in to comment.