Skip to content

Commit

Permalink
fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Jul 8, 2024
1 parent d541623 commit 6490e23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pepdbagent/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class HistoryProjects(Base):

project_mapping: Mapped["Projects"] = relationship(
"Projects", back_populates="history_mapping"
) # TODO: check if cascade is correct
)
sample_changes_mapping: Mapped[List["HistorySamples"]] = relationship(
back_populates="history_project_mapping", cascade="all, delete-orphan"
)
Expand Down
14 changes: 7 additions & 7 deletions pepdbagent/modules/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,32 +1235,32 @@ def get_project_from_history(
)

@staticmethod
def _apply_history_changes(sample_list: dict, change: HistoryProjects) -> dict:
def _apply_history_changes(sample_dict: dict, change: HistoryProjects) -> dict:
"""
Apply changes from the history to the sample list
:param sample_list: dictionary with samples
:param sample_dict: dictionary with samples
:param change: history change
:return: updated sample list
"""
for sample_change in change.sample_changes_mapping:
sample_id = sample_change.guid

if sample_change.change_type == UpdateTypes.UPDATE:
sample_list[sample_id]["sample"] = sample_change.sample_json
sample_list[sample_id]["parent_guid"] = sample_change.parent_guid
sample_dict[sample_id]["sample"] = sample_change.sample_json
sample_dict[sample_id]["parent_guid"] = sample_change.parent_guid

elif sample_change.change_type == UpdateTypes.DELETE:
sample_list[sample_id] = {
sample_dict[sample_id] = {
"sample": sample_change.sample_json,
"guid": sample_id,
"parent_guid": sample_change.parent_guid,
}

elif sample_change.change_type == UpdateTypes.INSERT:
del sample_list[sample_id]
del sample_dict[sample_id]

return sample_list
return sample_dict

def delete_history(
self, namespace: str, name: str, tag: str, history_id: Union[int, None] = None
Expand Down

0 comments on commit 6490e23

Please sign in to comment.