Skip to content

Commit

Permalink
General cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrondel committed Jan 17, 2025
1 parent 4ccd64e commit 33d3225
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion python/lsst/consdb/cdb_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def convert_to_flex_type(ty: AllowedFlexTypeEnum, v: str) -> AllowedFlexType:
if ty.value == "bool": # Special case
return v.lower() in ("true", "t", "1")
m = [t for t in AllowedFlexType.__args__ if t.__name__ == ty.value]
assert len(m) == 1

if len(m) != 1:
raise ValueError(f"Invalid type {ty.value} for conversion")

return m[0](v)


Expand Down
16 changes: 10 additions & 6 deletions python/lsst/consdb/handlers/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import astropy
import sqlalchemy
import sqlalchemy.dialects.postgresql
from fastapi import APIRouter, Body, Depends, Path, Query
from fastapi import APIRouter, Body, Depends, HTTPException, Path, Query
from packaging.version import Version
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -388,7 +388,7 @@ def get_all_metadata(
instrument: InstrumentName,
obs_type: ObsTypeEnum,
obs_id: ObservationIdType,
flex: int | None = Query(0, title="Include flexible metadata"),
flex: bool = Query(False, title="Include flexible metadata"),
db: Session = Depends(get_db),
logger: logging.Logger = Depends(get_logger),
instrument_table: InstrumentTable = Depends(get_instrument_table),
Expand All @@ -403,7 +403,7 @@ def get_all_metadata(
Name of the observation type (e.g. ``Exposure``).
obs_id: `int`
Unique observation identifier.
flex: `str`
flex: bool
Include flexible metadata if set to "1" (URL query parameter).
Returns
Expand All @@ -422,9 +422,13 @@ def get_all_metadata(
obs_id_column = instrument_table.obs_id_column[view_name]
result = dict()

rows = db.query(view).filter(view.c[obs_id_column] == obs_id).all()
assert len(rows) == 1
if flex != 0:
row = db.query(view).filter(view.c[obs_id_column] == obs_id).one_or_none()
if row is None:
raise HTTPException(status_code=404, detail=f"Observation {obs_id} not found.")

result = dict(row)

if flex:
flex_result = get_flexible_metadata(instrument, obs_type, obs_id)
result.update(flex_result)
return result
Expand Down
1 change: 0 additions & 1 deletion python/lsst/consdb/handlers/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def internal_root(
data types.
"""

assert instrument_list is not None
return IndexResponseModel.model_validate(
{
"name": config.name,
Expand Down

0 comments on commit 33d3225

Please sign in to comment.