From 1e79026abfa3b4ca7c30c585d55ecb6abfd8dd25 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Thu, 13 Jul 2023 12:59:24 -0400 Subject: [PATCH 1/6] fixed unfixable (hopefully) :D --- pepdbagent/db_utils.py | 4 ++-- pepdbagent/modules/project.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pepdbagent/db_utils.py b/pepdbagent/db_utils.py index 1aef1c1..78e4cb5 100644 --- a/pepdbagent/db_utils.py +++ b/pepdbagent/db_utils.py @@ -87,14 +87,14 @@ class Projects(Base): tag: Mapped[str] = mapped_column() digest: Mapped[str] = mapped_column(String(32)) description: Mapped[Optional[str]] = mapped_column( - default=deliver_description, onupdate=deliver_description + insert_default=deliver_description, onupdate=deliver_description ) config: Mapped[dict] = mapped_column(JSON, server_default=FetchedValue()) private: Mapped[bool] number_of_samples: Mapped[int] submission_date: Mapped[datetime.datetime] last_update_date: Mapped[Optional[datetime.datetime]] = mapped_column( - onupdate=deliver_update_date, + onupdate=deliver_update_date, insert_default=deliver_update_date ) pep_schema: Mapped[Optional[str]] samples_mapping: Mapped[List["Samples"]] = relationship( diff --git a/pepdbagent/modules/project.py b/pepdbagent/modules/project.py index 43170d8..cd7d6d3 100644 --- a/pepdbagent/modules/project.py +++ b/pepdbagent/modules/project.py @@ -266,6 +266,7 @@ def create( submission_date=datetime.datetime.now(datetime.timezone.utc), last_update_date=datetime.datetime.now(datetime.timezone.utc), pep_schema=pep_schema, + # description=proj_dict[CONFIG_KEY].get("description") ) self._add_samples_to_project(new_prj, proj_dict[SAMPLE_RAW_DICT_KEY]) @@ -332,7 +333,7 @@ def _overwrite( statement = self._create_select_statement(proj_name, namespace, tag) with Session(self._sa_engine) as session: - found_prj = session.scalars(statement).one() + found_prj = session.scalar(statement) if found_prj: _LOGGER.debug( From aa8e51834fb81ee86405687d49127b55cc698197 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Thu, 13 Jul 2023 13:11:54 -0400 Subject: [PATCH 2/6] fixed unfixable (hopefully2) :D --- pepdbagent/modules/project.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pepdbagent/modules/project.py b/pepdbagent/modules/project.py index cd7d6d3..319f4bb 100644 --- a/pepdbagent/modules/project.py +++ b/pepdbagent/modules/project.py @@ -266,7 +266,6 @@ def create( submission_date=datetime.datetime.now(datetime.timezone.utc), last_update_date=datetime.datetime.now(datetime.timezone.utc), pep_schema=pep_schema, - # description=proj_dict[CONFIG_KEY].get("description") ) self._add_samples_to_project(new_prj, proj_dict[SAMPLE_RAW_DICT_KEY]) @@ -452,6 +451,8 @@ def update( if update_dict["subsamples"]: self._add_subsamples_to_project(found_prj, update_dict["subsamples"]) + found_prj.last_update_date = datetime.datetime.now(datetime.timezone.utc) + session.commit() return None From 9476b062b1a350608291aaf16226a52d2ebe8d60 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Thu, 13 Jul 2023 15:28:51 -0400 Subject: [PATCH 3/6] =?UTF-8?q?fixed=20unfixable=20(hopefully3)=20?= =?UTF-8?q?=E0=B2=A5=20=5F=CA=96=20=E0=B2=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pepdbagent/db_utils.py | 13 +++------ pepdbagent/models.py | 2 ++ pepdbagent/modules/project.py | 51 ++++++++++++++++++++++++----------- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/pepdbagent/db_utils.py b/pepdbagent/db_utils.py index 78e4cb5..e758ea1 100644 --- a/pepdbagent/db_utils.py +++ b/pepdbagent/db_utils.py @@ -63,11 +63,8 @@ def receive_after_create(target, connection, tables, **kw): _LOGGER.info("A table was not created") -def deliver_description(context): - try: - return context.get_current_parameters()["config"]["description"] - except KeyError: - return "" +# def deliver_description(context): +# return context.get_current_parameters()["config"]["description"] def deliver_update_date(context): @@ -86,15 +83,13 @@ class Projects(Base): name: Mapped[str] = mapped_column() tag: Mapped[str] = mapped_column() digest: Mapped[str] = mapped_column(String(32)) - description: Mapped[Optional[str]] = mapped_column( - insert_default=deliver_description, onupdate=deliver_description - ) + description: Mapped[Optional[str]] config: Mapped[dict] = mapped_column(JSON, server_default=FetchedValue()) private: Mapped[bool] number_of_samples: Mapped[int] submission_date: Mapped[datetime.datetime] last_update_date: Mapped[Optional[datetime.datetime]] = mapped_column( - onupdate=deliver_update_date, insert_default=deliver_update_date + onupdate=deliver_update_date, default=deliver_update_date ) pep_schema: Mapped[Optional[str]] samples_mapping: Mapped[List["Samples"]] = relationship( diff --git a/pepdbagent/models.py b/pepdbagent/models.py index d07337e..d9ad64a 100644 --- a/pepdbagent/models.py +++ b/pepdbagent/models.py @@ -80,6 +80,7 @@ class UpdateItems(BaseModel): config: Optional[dict] samples: Optional[List[dict]] subsamples: Optional[List[List[dict]]] + description: Optional[str] class Config: arbitrary_types_allowed = True @@ -105,6 +106,7 @@ class UpdateModel(BaseModel): digest: Optional[str] number_of_samples: Optional[int] pep_schema: Optional[str] + description: Optional[str] = "" # last_update_date: Optional[datetime.datetime] = datetime.datetime.now(datetime.timezone.utc) @validator("tag", "name") diff --git a/pepdbagent/modules/project.py b/pepdbagent/modules/project.py index 319f4bb..af05c84 100644 --- a/pepdbagent/modules/project.py +++ b/pepdbagent/modules/project.py @@ -228,14 +228,14 @@ def create( namespace = namespace.lower() if name: - name = name.lower() - proj_name = name - proj_dict[CONFIG_KEY]["name"] = proj_name + proj_name = name.lower() elif proj_dict[CONFIG_KEY]["name"]: proj_name = proj_dict[CONFIG_KEY]["name"].lower() else: raise ValueError(f"Name of the project wasn't provided. Project will not be uploaded.") + proj_dict[CONFIG_KEY]["name"] = proj_name + proj_digest = create_digest(proj_dict) number_of_samples = len(project.samples) @@ -250,6 +250,7 @@ def create( number_of_samples=number_of_samples, private=is_private, pep_schema=pep_schema, + description=description, ) return None else: @@ -266,6 +267,7 @@ def create( submission_date=datetime.datetime.now(datetime.timezone.utc), last_update_date=datetime.datetime.now(datetime.timezone.utc), pep_schema=pep_schema, + description=description, ) self._add_samples_to_project(new_prj, proj_dict[SAMPLE_RAW_DICT_KEY]) @@ -311,6 +313,7 @@ def _overwrite( number_of_samples: int, private: bool = False, pep_schema: str = None, + description: str = "", ) -> None: """ Update existing project by providing all necessary information. @@ -323,6 +326,7 @@ def _overwrite( :param number_of_samples: number of samples in project :param private: boolean value if the project should be visible just for user that creates it. :param pep_schema: assign PEP to a specific schema. [DefaultL: None] + :param description: project description :return: None """ proj_name = proj_name.lower() @@ -343,8 +347,8 @@ def _overwrite( found_prj.number_of_samples = number_of_samples found_prj.private = private found_prj.pep_schema = pep_schema - found_prj.last_update_date = datetime.datetime.now(datetime.timezone.utc) - found_prj.description = project_dict[CONFIG_KEY].get("description") + found_prj.config = project_dict[CONFIG_KEY] + found_prj.description = description # Deleting old samples and subsamples if found_prj.samples_mapping: @@ -472,14 +476,37 @@ def __create_update_dict(update_values: UpdateItems) -> dict: """ update_final = UpdateModel() - if update_values.config is not None: - if update_values.description is not None: - update_values.config["description"] = update_values.description - if update_values.name is not None: + if update_values.name is not None: + if update_values.config is not None: update_values.config["name"] = update_values.name + update_final = UpdateModel( + name=update_values.name, + **update_final.dict(exclude_unset=True), + ) + + if update_values.description is not None: + if update_values.config is not None: + update_values.config["description"] = update_values.description + update_final = UpdateModel( + description=update_values.description, + **update_final.dict(exclude_unset=True), + ) + if update_values.config is not None: update_final = UpdateModel( config=update_values.config, **update_final.dict(exclude_unset=True) ) + name = update_values.config.get("name") + description = update_values.config.get("description") + if name: + update_final = UpdateModel( + name=name, + **update_final.dict(exclude_unset=True, exclude={"name"}), + ) + if description: + update_final = UpdateModel( + description=description, + **update_final.dict(exclude_unset=True, exclude={"description"}), + ) if update_values.tag is not None: update_final = UpdateModel( @@ -492,12 +519,6 @@ def __create_update_dict(update_values: UpdateItems) -> dict: **update_final.dict(exclude_unset=True), ) - if update_values.name is not None: - update_final = UpdateModel( - name=update_values.name, - **update_final.dict(exclude_unset=True), - ) - if update_values.pep_schema is not None: update_final = UpdateModel( pep_schema=update_values.pep_schema, From 61a42fbe73cc7834b26d67dbb019f793f62e215e Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Thu, 13 Jul 2023 15:34:53 -0400 Subject: [PATCH 4/6] =?UTF-8?q?fixed=20unfixable=20(hopefully4)=20(=20?= =?UTF-8?q?=E2=80=98=CC=81=E2=8C=A3=E2=80=99=CC=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pepdbagent/modules/project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pepdbagent/modules/project.py b/pepdbagent/modules/project.py index af05c84..25cc027 100644 --- a/pepdbagent/modules/project.py +++ b/pepdbagent/modules/project.py @@ -293,6 +293,7 @@ def create( number_of_samples=number_of_samples, private=is_private, pep_schema=pep_schema, + description=description, ) return None From e84a345507ee7c0a6da05e7340c6386c5edf0329 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Thu, 13 Jul 2023 15:44:24 -0400 Subject: [PATCH 5/6] updated version --- docs/changelog.md | 3 +++ pepdbagent/_version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 0d4de96..38885a4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format. +## [0.5.3] -- 2023-07-13 +- Fixed bugs in updating dates and descriptions + ## [0.5.2] -- 2023-07-13 - Fixed error in updating date in overwriting function diff --git a/pepdbagent/_version.py b/pepdbagent/_version.py index 7225152..43a1e95 100644 --- a/pepdbagent/_version.py +++ b/pepdbagent/_version.py @@ -1 +1 @@ -__version__ = "0.5.2" +__version__ = "0.5.3" From 888f6d04d7073a112d3926d0ea18da778069f872 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Thu, 13 Jul 2023 19:58:13 -0400 Subject: [PATCH 6/6] updated const --- pepdbagent/const.py | 1 + pepdbagent/modules/project.py | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pepdbagent/const.py b/pepdbagent/const.py index 2a073c4..185364b 100644 --- a/pepdbagent/const.py +++ b/pepdbagent/const.py @@ -4,6 +4,7 @@ DEFAULT_TAG = "default" DESCRIPTION_KEY = "description" +NAME_KEY = "name" # from peppy.const import SAMPLE_RAW_DICT_KEY, SUBSAMPLE_RAW_LIST_KEY diff --git a/pepdbagent/modules/project.py b/pepdbagent/modules/project.py index 25cc027..3ccbeb5 100644 --- a/pepdbagent/modules/project.py +++ b/pepdbagent/modules/project.py @@ -224,17 +224,17 @@ def create( proj_dict = project.to_dict(extended=True, orient="records") if not description: description = project.description - proj_dict[CONFIG_KEY]["description"] = description + proj_dict[CONFIG_KEY][DESCRIPTION_KEY] = description namespace = namespace.lower() if name: proj_name = name.lower() - elif proj_dict[CONFIG_KEY]["name"]: - proj_name = proj_dict[CONFIG_KEY]["name"].lower() + elif proj_dict[CONFIG_KEY][NAME_KEY]: + proj_name = proj_dict[CONFIG_KEY][NAME_KEY].lower() else: raise ValueError(f"Name of the project wasn't provided. Project will not be uploaded.") - proj_dict[CONFIG_KEY]["name"] = proj_name + proj_dict[CONFIG_KEY][NAME_KEY] = proj_name proj_digest = create_digest(proj_dict) number_of_samples = len(project.samples) @@ -431,12 +431,12 @@ def update( setattr(found_prj, k, v) # standardizing project name - if k == "name": + if k == NAME_KEY: if "config" in update_values: - update_values["config"]["name"] = v + update_values["config"][NAME_KEY] = v else: - found_prj.config["name"] = v - found_prj.name = found_prj.config["name"] + found_prj.config[NAME_KEY] = v + found_prj.name = found_prj.config[NAME_KEY] if "samples" in update_dict: if found_prj.samples_mapping: @@ -479,7 +479,7 @@ def __create_update_dict(update_values: UpdateItems) -> dict: if update_values.name is not None: if update_values.config is not None: - update_values.config["name"] = update_values.name + update_values.config[NAME_KEY] = update_values.name update_final = UpdateModel( name=update_values.name, **update_final.dict(exclude_unset=True), @@ -487,7 +487,7 @@ def __create_update_dict(update_values: UpdateItems) -> dict: if update_values.description is not None: if update_values.config is not None: - update_values.config["description"] = update_values.description + update_values.config[DESCRIPTION_KEY] = update_values.description update_final = UpdateModel( description=update_values.description, **update_final.dict(exclude_unset=True), @@ -496,17 +496,17 @@ def __create_update_dict(update_values: UpdateItems) -> dict: update_final = UpdateModel( config=update_values.config, **update_final.dict(exclude_unset=True) ) - name = update_values.config.get("name") - description = update_values.config.get("description") + name = update_values.config.get(NAME_KEY) + description = update_values.config.get(DESCRIPTION_KEY) if name: update_final = UpdateModel( name=name, - **update_final.dict(exclude_unset=True, exclude={"name"}), + **update_final.dict(exclude_unset=True, exclude={NAME_KEY}), ) if description: update_final = UpdateModel( description=description, - **update_final.dict(exclude_unset=True, exclude={"description"}), + **update_final.dict(exclude_unset=True, exclude={DESCRIPTION_KEY}), ) if update_values.tag is not None: