From 7588e6ee28b70996c4ee421d8eb7e64e3a1fd2fc Mon Sep 17 00:00:00 2001 From: Peter Bednarik Date: Thu, 5 Feb 2026 14:33:25 +0200 Subject: [PATCH 1/2] Cosmetic changes. --- desdeo/api/models/problem.py | 13 +++++++++---- desdeo/api/routers/problem.py | 18 +++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/desdeo/api/models/problem.py b/desdeo/api/models/problem.py index ff7a382ef..d7301fd09 100644 --- a/desdeo/api/models/problem.py +++ b/desdeo/api/models/problem.py @@ -254,10 +254,15 @@ class RepresentativeNonDominatedSolutions(RepresentativeSolutionSetBase, SQLMode metadata_id: int | None = Field(foreign_key="problemmetadatadb.id", default=None) metadata_type: str = "representative_non_dominated_solutions" - solution_data: dict[str, list[float]] = Field(sa_column=Column(JSON)) - ideal: dict[str, float] = Field(sa_column=Column(JSON)) - nadir: dict[str, float] = Field(sa_column=Column(JSON)) - + solution_data: dict[str, list[float]] = Field(sa_column=Column(JSON), + description="The non-dominated solutions. It is assumed that columns " + "exist for each variable and objective function. For functions, the " + "`_min` variant should be present, and any tensor variables should be " + "unrolled.") + ideal: dict[str, float] = Field(sa_column=Column(JSON), + description="The ideal objective function values of the representative set.") + nadir: dict[str, float] = Field(sa_column=Column(JSON), + description="The nadir objective function values of the representative set.") metadata_instance: "ProblemMetaDataDB" = Relationship(back_populates="representative_nd_metadata") diff --git a/desdeo/api/routers/problem.py b/desdeo/api/routers/problem.py index 9d85960f2..129194dec 100644 --- a/desdeo/api/routers/problem.py +++ b/desdeo/api/routers/problem.py @@ -329,13 +329,13 @@ def select_solver( response_model=RepresentativeSolutionSetInfo ) def add_representative_solution_set( - payload: RepresentativeSolutionSetRequest, + request: RepresentativeSolutionSetRequest, context: Annotated[SessionContext, Depends(get_session_context_without_request)], ): """Add a new representative solution set as metadata to a problem. Args: - payload (RepresentativeSolutionSetRequest): The JSON body containing the + request (RepresentativeSolutionSetRequest): The JSON body containing the details of the representative solution set (name, description, solution data, ideal, nadir). context (SessionContext): The session context providing the current user and database session. @@ -349,9 +349,9 @@ def add_representative_solution_set( db_session: Session = context.db_session # Fetch the problem - problem_db = db_session.get(ProblemDB, payload.problem_id) + problem_db = db_session.get(ProblemDB, request.problem_id) if problem_db is None: - raise HTTPException(status_code=404, detail=f"Problem with ID {payload.problem_id} not found.") + raise HTTPException(status_code=404, detail=f"Problem with ID {request.problem_id} not found.") # Check the user if user.id != problem_db.user_id: @@ -369,11 +369,11 @@ def add_representative_solution_set( # Add new representative solution set repr_metadata = RepresentativeNonDominatedSolutions( metadata_id=problem_metadata.id, - name=payload.name, - description=payload.description, - solution_data=payload.solution_data, - ideal=payload.ideal, - nadir=payload.nadir, + name=request.name, + description=request.description, + solution_data=request.solution_data, + ideal=request.ideal, + nadir=request.nadir, metadata_instance=problem_metadata, ) From 1b3688f3fdb527ec80bcfb604140dea63fdf7e5f Mon Sep 17 00:00:00 2001 From: Peter Bednarik Date: Mon, 9 Feb 2026 10:07:01 +0200 Subject: [PATCH 2/2] Request type enhanced with RepresentativeSolutionSetRequest and add_repr_solution endpoint uses get_session_context --- desdeo/api/routers/problem.py | 12 +++--------- desdeo/api/routers/utils.py | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/desdeo/api/routers/problem.py b/desdeo/api/routers/problem.py index 129194dec..e4167705e 100644 --- a/desdeo/api/routers/problem.py +++ b/desdeo/api/routers/problem.py @@ -330,7 +330,7 @@ def select_solver( ) def add_representative_solution_set( request: RepresentativeSolutionSetRequest, - context: Annotated[SessionContext, Depends(get_session_context_without_request)], + context: Annotated[SessionContext, Depends(get_session_context)], ): """Add a new representative solution set as metadata to a problem. @@ -345,17 +345,11 @@ def add_representative_solution_set( Returns: dict: Confirmation message. """ - user = context.user db_session: Session = context.db_session + problem_db = context.problem_db - # Fetch the problem - problem_db = db_session.get(ProblemDB, request.problem_id) if problem_db is None: - raise HTTPException(status_code=404, detail=f"Problem with ID {request.problem_id} not found.") - - # Check the user - if user.id != problem_db.user_id: - raise HTTPException(status_code=401, detail="Unauthorized user.") + raise HTTPException(status_code=500, detail="Problem context missing.") # Ensure metadata object exists if problem_db.problem_metadata is None: diff --git a/desdeo/api/routers/utils.py b/desdeo/api/routers/utils.py index 0d8511498..54fafafa8 100644 --- a/desdeo/api/routers/utils.py +++ b/desdeo/api/routers/utils.py @@ -18,9 +18,10 @@ StateDB, User, ) +from desdeo.api.models.representative_solution import RepresentativeSolutionSetRequest from desdeo.api.routers.user_authentication import get_current_user -RequestType = RPMSolveRequest | ENautilusStepRequest +RequestType = RPMSolveRequest | ENautilusStepRequest | RepresentativeSolutionSetRequest def fetch_interactive_session(user: User, request: RequestType, session: Session) -> InteractiveSessionDB | None: