openclimatefix / uk-pv-national-gsp-api

API for hosting nowcasting solar predictions
MIT License
6 stars 10 forks source link

/v0/solar/GB/gsp/forecast/all endpoint returns 422 status #362

Open pwdemars opened 1 month ago

pwdemars commented 1 month ago

Describe the bug

Hitting the /v0/solar/GB/gsp/forecast/all endpoint returns status 422 with pydantic error around 'all' not being an integer. Issue appears to be around the overlap between this endpoint and /v0/solar/GB/gsp/forecast/{gsp_id}

To Reproduce

Running

url = "https://api.quartz.solar/v0/solar/GB/gsp/forecast/all"
r = requests.get(url=url,headers={"Authorization": "Bearer "+access_token})
r.content

Returns a 422 status code with content:

{"detail":[{"type":"int_parsing","loc":["path","gsp_id"],"msg":"Input should be a valid integer, unable to parse string as an integer","input":"all"}]}

Expected behavior

Should receive 200 code with GSP latest forecasts

Additional context

I guess this may have something to do with the old forecast/{gsp_id} endpoint, which enforces type gsp_id: str and throws an error. See function below:

@router.get(
    "/forecast/{gsp_id}",
    response_model=Union[Forecast, List[ForecastValue]],
    dependencies=[Depends(get_auth_implicit_scheme())],
    include_in_schema=False,
    responses={status.HTTP_204_NO_CONTENT: {"model": None}},
)
@cache_response
@limiter.limit(f"{N_CALLS_PER_HOUR}/hour")
def get_forecasts_for_a_specific_gsp_old_route(
    request: Request,
    gsp_id: int,
    session: Session = Depends(get_session),
    forecast_horizon_minutes: Optional[int] = None,
    user: Auth0User = Security(get_user()),
) -> Union[Forecast, List[ForecastValue]]:
    """Redirects old API route to new route /v0/solar/GB/gsp/{gsp_id}/forecast"""
    return get_forecasts_for_a_specific_gsp(
        request=request,
        gsp_id=gsp_id,
        session=session,
        forecast_horizon_minutes=forecast_horizon_minutes,
        user=user,
    )

There could be a quick fix in redirecting to get_all_available_forecasts() if gsp_id=='all' but this seems janky. Plus they don't have the same parameters.

Also very possible (likely??) I am doing something wrong myself !

peterdudfield commented 1 month ago

Thanks @pwdemars for reporting this. We can defiantly fix this. In the mean time if you use url = "https://api.quartz.solar/v0/solar/GB/gsp/forecast/all/" with a forward slack at the end it works ok.