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

fix(create): fix crash when no project is on the server (DEV-3405) #875

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/dsp_tools/commands/project/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

from dsp_tools.commands.project.models.model import Model
from dsp_tools.models.exceptions import BaseError
from dsp_tools.models.exceptions import InputError
from dsp_tools.models.langstring import LangString
from dsp_tools.utils.connection import Connection
from dsp_tools.utils.create_logger import get_logger

logger = get_logger(__name__)
Nora-Olivia-Ammann marked this conversation as resolved.
Show resolved Hide resolved


class Project(Model):
Expand Down Expand Up @@ -352,7 +356,8 @@ def getAllProjects(con: Connection) -> list[Project]:
:param con: Connection instance
:return:
"""
result = con.get(Project.ROUTE)
if "projects" not in result:
raise BaseError("Request got no projects!")
return [Project.fromJsonObj(con, a) for a in result["projects"]]
try:
result = con.get(Project.ROUTE)
return [Project.fromJsonObj(con, a) for a in result["projects"]]
except InputError:
return []
1 change: 1 addition & 0 deletions src/dsp_tools/utils/connection_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def _handle_non_ok_responses(self, response: Response, request_url: str, retry_c
r"OntologyConstraintException",
r"DuplicateValueException",
r"Project '[0-9A-F]{4}' not found",
r"No projects found",
]
if "v2/authentication" in request_url and response.status_code == HTTP_UNAUTHORIZED:
raise BadCredentialsError("Bad credentials")
Expand Down
2 changes: 1 addition & 1 deletion test/integration/commands/project/test_models_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_return_values(project: Project) -> None:
assert project.keywords == set()


def test__toJsonObj_create(project: Project) -> None:
def test_toJsonObj_create(project: Project) -> None:
res_json = project._toJsonObj_create()
expected = {
"shortcode": "0FF0",
Expand Down