Skip to content

Commit

Permalink
feat(study-search): improve access to session in update_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-laporte-pro committed Feb 22, 2024
1 parent ab7502f commit dc252a1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions antarest/study/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,18 @@ def update_tags(self, study: Study, new_tags: t.Sequence[str]) -> None:
new_tags: The new tags to be associated with the input study in the database.
"""
new_upper_tags = {tag.upper(): tag for tag in new_tags}
existing_tags = self.session.query(Tag).filter(func.upper(Tag.label).in_(new_upper_tags)).all()
session = self.session
existing_tags = session.query(Tag).filter(func.upper(Tag.label).in_(new_upper_tags)).all()
for tag in existing_tags:
if tag.label.upper() in new_upper_tags:
new_upper_tags.pop(tag.label.upper())
study.tags = [Tag(label=tag) for tag in new_upper_tags.values()] + existing_tags
self.session.merge(study)
self.session.commit()
session.merge(study)
session.commit()
# Delete any tag that is not associated with any study.
# Note: If tags are to be associated with objects other than Study, this code must be updated.
self.session.query(Tag).filter(~Tag.studies.any()).delete(synchronize_session=False) # type: ignore
self.session.commit()
session.query(Tag).filter(~Tag.studies.any()).delete(synchronize_session=False) # type: ignore
session.commit()

def list_duplicates(self) -> t.List[t.Tuple[str, str]]:
"""
Expand Down

0 comments on commit dc252a1

Please sign in to comment.