Skip to content

Commit

Permalink
Fixed #243
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Dec 11, 2023
1 parent 419daf5 commit 815876f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pephub/routers/api/v1/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async def upload_raw_pep(

# This configurations needed due to Issue #124 Should be removed in the future
project_dict = ProjectRawModel(**project_from_json.pep_dict.dict())
ff = project_dict.dict(by_alias=True)
ff = project_dict.model_dump(by_alias=True)
p_project = peppy.Project().from_dict(ff)

p_project.name = name
Expand Down
8 changes: 4 additions & 4 deletions pephub/routers/api/v1/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def get_a_pep(
raw_project = ProjectRawModel(**proj)
except Exception:
raise HTTPException(500, "Unexpected project error!")
return raw_project.dict(by_alias=False)
return raw_project.model_dump(by_alias=False)
samples = [s.to_dict() for s in proj.samples]
sample_table_index = proj.sample_table_index

Expand All @@ -75,7 +75,7 @@ async def get_a_pep(
sample_attributes = proj._samples[0]._attributes

proj_dict = proj.to_dict()
proj_annotation_dict = proj_annotation.dict()
proj_annotation_dict = proj_annotation.model_dump()

# default to name from annotation
if hasattr(proj, "name") and hasattr(proj_annotation, "name"):
Expand Down Expand Up @@ -202,7 +202,7 @@ async def update_a_pep(

# update "meta meta data"
update_dict = {} # dict used to pass to the `db.update_item` function
for k, v in updated_project.dict(exclude_unset=True).items():
for k, v in updated_project.model_dump(exclude_unset=True).items():
# is the value an attribute of the peppy project?
if k in new_raw_project:
new_raw_project[k] = v
Expand Down Expand Up @@ -237,7 +237,7 @@ async def update_a_pep(
# "project": raw_peppy_project,
"registry": f"{namespace}/{project}:{tag}",
"api_endpoint": f"/api/v1/namespaces/{namespace}/{project}",
"project": updated_project.dict(),
"project": updated_project.model_dump(),
},
status_code=202,
)
Expand Down
26 changes: 11 additions & 15 deletions pephub/routers/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Optional, List
from pydantic import BaseModel, Field, Extra
from pydantic import BaseModel, Field, ConfigDict
from pepdbagent.models import UpdateItems
from pepdbagent.const import DEFAULT_TAG

Expand All @@ -8,13 +8,12 @@

class ProjectOptional(UpdateItems):
# sample table is a list of JSON objects
sample_table: Optional[List[dict]]
project_config_yaml: Optional[str]
description: Optional[str]
subsample_tables: Optional[List[List[dict]]]
sample_table: Optional[List[dict]] = None
project_config_yaml: Optional[str] = None
description: Optional[str] = None
subsample_tables: Optional[List[List[dict]]] = None

class Config:
allow_population_by_field_name = True
model_config = ConfigDict(populate_by_name=True)


class SearchQuery(BaseModel):
Expand All @@ -27,7 +26,7 @@ class SearchQuery(BaseModel):

class RawValidationQuery(BaseModel):
project_config: str
sample_table: Optional[str]
sample_table: Optional[str] = None


class TokenExchange(BaseModel):
Expand Down Expand Up @@ -60,21 +59,18 @@ class JWTDeviceTokenResponse(BaseModel):

class ProjectRawModel(BaseModel):
config: dict = Field(alias="_config")
subsample_list: Optional[list] = Field(alias="_subsample_list")
subsample_list: Optional[list] = Field(alias="_subsample_list", default=None)
sample_list: list[dict] = Field(alias="_sample_dict")

class Config:
allow_population_by_field_name = True
model_config = ConfigDict(populate_by_name=True)


class ProjectRawRequest(BaseModel):
config: dict
subsample_list: Optional[List[List[dict]]]
subsample_list: Optional[List[List[dict]]] = None
sample_list: List[dict]

class Config:
allow_population_by_field_name = True
extra = Extra.allow
model_config = ConfigDict(populate_by_name=True, extra="allow")


class ProjectJsonRequest(BaseModel):
Expand Down

0 comments on commit 815876f

Please sign in to comment.