Fix type and handle missing dewar_id in sample router.
Updated puck_id type from str to int for better type consistency. Added a fallback value of -1 for pucks with missing dewar_id to prevent potential errors when querying pucks.
This commit is contained in:
@ -22,7 +22,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/{puck_id}/samples", response_model=List[SampleSchema])
|
||||
async def get_samples_with_events(puck_id: str, db: Session = Depends(get_db)):
|
||||
async def get_samples_with_events(puck_id: int, db: Session = Depends(get_db)):
|
||||
puck = db.query(PuckModel).filter(PuckModel.id == puck_id).first()
|
||||
if not puck:
|
||||
raise HTTPException(status_code=404, detail="Puck not found")
|
||||
@ -46,6 +46,8 @@ async def get_all_pucks_with_samples_and_events(db: Session = Depends(get_db)):
|
||||
pucks = db.query(PuckModel).all()
|
||||
logging.info(f"Found {len(pucks)} pucks in the database")
|
||||
for puck in pucks:
|
||||
if puck.dewar_id is None:
|
||||
puck.dewar_id = -1
|
||||
logging.info(f"Puck ID: {puck.id}, Name: {puck.puck_name}")
|
||||
|
||||
if not pucks:
|
||||
|
Reference in New Issue
Block a user