Skip to content

Commit 19cd3f7

Browse files
refactor(deposition): rename variables for clarity, avoid mutating (#6454)
We came across this code when discussing what happens if submitters have multiple custom bioprojects. Just a few small tweaks to variable names and avoiding mutation for clarity. Things that could be >1 had variable names that implied it was at most one, etc.
1 parent 854ae17 commit 19cd3f7

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

ena-submission/src/ena_deposition/create_project.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def update_with_existing_bioproject(
144144
def sync_state_with_submission_table(db_engine: Engine):
145145
"""
146146
1. Find all entries in submission_table in state READY_TO_SUBMIT
147-
2. If (exists an entry in the project_table for (group_id, organism)):
147+
2. If (exists entry/entries in the project_table for (group_id, organism)):
148148
a. If (exists "bioproject" in "metadata") filter to that entry
149149
b. If (in state SUBMITTED) update state in submission_table to SUBMITTED_PROJECT
150150
3. Else create corresponding entry in project_table in state READY
@@ -158,20 +158,23 @@ def sync_state_with_submission_table(db_engine: Engine):
158158
for row in ready_to_submit:
159159
group_key = {"group_id": row.group_id, "organism": row.organism}
160160
seq_key = asdict(row.pkey)
161-
bioproject = row.seq_metadata.get("bioprojectAccession")
161+
submitter_provided_bioproject: str | None = row.seq_metadata.get("bioprojectAccession")
162162

163-
# Check if there exists an entry in the project table for (group_id, organism)
164-
corresponding_project = find_conditions_in_db(
163+
# Check if there exist entries in the project table for (group_id, organism)
164+
existing_corresponding_projects = find_conditions_in_db(
165165
db_engine, ProjectTableEntry, conditions=group_key
166166
)
167167

168168
# Use custom bioprojectAccession if it exists
169-
if bioproject:
169+
if submitter_provided_bioproject:
170170
corresponding_project = [
171171
project
172-
for project in corresponding_project
173-
if project.result and project.result.get("bioproject_accession") == bioproject
172+
for project in existing_corresponding_projects
173+
if project.result
174+
and project.result.get("bioproject_accession") == submitter_provided_bioproject
174175
]
176+
else:
177+
corresponding_project = existing_corresponding_projects
175178

176179
if len(corresponding_project) == 1 and corresponding_project[0].status == str(
177180
Status.SUBMITTED
@@ -207,7 +210,9 @@ def sync_state_with_submission_table(db_engine: Engine):
207210
ProjectTableEntry(
208211
group_id=row.group_id,
209212
organism=row.organism,
210-
result={"bioproject_accession": bioproject} if bioproject else None,
213+
result={"bioproject_accession": submitter_provided_bioproject}
214+
if submitter_provided_bioproject
215+
else None,
211216
),
212217
)
213218
if not project_id:

0 commit comments

Comments
 (0)