Skip to content

Commit 70c0d8e

Browse files
committed
replace CellNotFound
1 parent c436799 commit 70c0d8e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/db/crud.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os, json
44

55
import gspread
6-
from gspread.exceptions import CellNotFound
76
from oauth2client.service_account import ServiceAccountCredentials
87
from sqlalchemy.orm import Session
98
from sqlalchemy import func
@@ -47,10 +46,12 @@ def submit_task(db: Session, mentee_id: int, task_id: int, start_date: date, com
4746
task = db.query(models.Task).filter(models.Task.id == task_id).first()
4847
if not task:
4948
raise Exception("Task not found")
49+
5050
submitted_at = date.today()
5151
deadline = start_date + timedelta(days=task.deadline_days or 0) if task.deadline_days else None
5252
if deadline and submitted_at > deadline:
5353
return "late submission not allowed"
54+
5455
submission = models.Submission(
5556
mentee_id=mentee_id,
5657
task_id=task.id,
@@ -61,19 +62,23 @@ def submit_task(db: Session, mentee_id: int, task_id: int, start_date: date, com
6162
start_date=start_date,
6263
commit_hash=commit_hash,
6364
)
65+
6466
client = _gspread_client()
6567
if task.track_id in (1, 2):
6668
sheet = client.open("Copy of Praveshan 2025 Master DB").worksheet(
6769
"S1 Submissions" if task.track_id == 1 else "S2 Submissions"
6870
)
71+
72+
# find/create row for mentee.name in column A without using CellNotFound
73+
name_column = sheet.col_values(1)
6974
try:
70-
cell = sheet.find(mentee.name)
71-
row = cell.row
72-
except CellNotFound:
73-
name_column = sheet.col_values(1)
75+
row = name_column.index(mentee.name) + 1 # 1-based row
76+
except ValueError:
7477
row = len(name_column) + 1 if name_column else 1
7578
sheet.update_cell(row, 1, mentee.name)
79+
7680
sheet.update_cell(row, task.task_no + 2, commit_hash)
81+
7782
db.add(submission)
7883
db.commit()
7984
db.refresh(submission)

0 commit comments

Comments
 (0)