From 90136b989a8918c643f73fb03aa399116bfde615 Mon Sep 17 00:00:00 2001 From: ashnaaseth2325-oss Date: Wed, 18 Mar 2026 13:49:35 +0000 Subject: [PATCH 1/4] fix: guard map lookup in buildTripReferences Use comma-ok on presentRoutes to skip trips whose route ID is not populated, preventing silent empty AgencyID in combined IDs. Signed-off-by: ashnaaseth2325-oss --- internal/restapi/trips_for_location_handler.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/restapi/trips_for_location_handler.go b/internal/restapi/trips_for_location_handler.go index dc877f1e..3786b3f8 100644 --- a/internal/restapi/trips_for_location_handler.go +++ b/internal/restapi/trips_for_location_handler.go @@ -716,8 +716,11 @@ func (rb *referenceBuilder) buildTripReferences() error { continue } - currentAgency := rb.presentRoutes[tripDetails.RouteID].AgencyID - rb.tripsRefList = append(rb.tripsRefList, rb.createTripReference(tripDetails, currentAgency, trip)) + route, ok := rb.presentRoutes[tripDetails.RouteID] + if !ok { + continue + } + rb.tripsRefList = append(rb.tripsRefList, rb.createTripReference(tripDetails, route.AgencyID, trip)) } return nil } From d45c7929509e050b6bae6b9c1fc9b9ac801a9565 Mon Sep 17 00:00:00 2001 From: ashnaaseth2325-oss Date: Fri, 20 Mar 2026 11:44:17 +0000 Subject: [PATCH 2/4] fix: return stopSequence on block trips DB error Signed-off-by: ashnaaseth2325-oss --- internal/restapi/block_sequence_helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/restapi/block_sequence_helper.go b/internal/restapi/block_sequence_helper.go index 47760d5c..2696f897 100644 --- a/internal/restapi/block_sequence_helper.go +++ b/internal/restapi/block_sequence_helper.go @@ -17,7 +17,7 @@ func (api *RestAPI) getBlockSequenceForStopSequence(ctx context.Context, tripID blockTrips, err := api.GtfsManager.GtfsDB.Queries.GetTripsByBlockID(ctx, blockID) if err != nil { - return 0 + return stopSequence } type TripWithDetails struct { From bde7cb867a0298e341f9641c81c3ad77dbe12670 Mon Sep 17 00:00:00 2001 From: ashnaaseth2325-oss Date: Fri, 20 Mar 2026 11:44:43 +0000 Subject: [PATCH 3/4] fix: use combined IDs for routeId and serviceId in schedule-for-route trip refs Signed-off-by: ashnaaseth2325-oss --- internal/restapi/schedule_for_route_handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/restapi/schedule_for_route_handler.go b/internal/restapi/schedule_for_route_handler.go index 2f6e117c..101a0fd6 100644 --- a/internal/restapi/schedule_for_route_handler.go +++ b/internal/restapi/schedule_for_route_handler.go @@ -254,8 +254,8 @@ func (api *RestAPI) scheduleForRouteHandler(w http.ResponseWriter, r *http.Reque combinedTripID := utils.FormCombinedID(agencyID, t.ID) tripRef := models.NewTripReference( combinedTripID, - t.RouteID, - t.ServiceID, + utils.FormCombinedID(agencyID, t.RouteID), + utils.FormCombinedID(agencyID, t.ServiceID), t.TripHeadsign.String, t.TripShortName.String, strconv.FormatInt(t.DirectionID.Int64, 10), From 4c40078d831944c10100034392b98217263ed8c3 Mon Sep 17 00:00:00 2001 From: ashnaaseth2325-oss Date: Fri, 20 Mar 2026 12:13:06 +0000 Subject: [PATCH 4/4] test: clear service-IDs cache before inserting test calendar in VehicleWithNilID test Signed-off-by: ashnaaseth2325-oss --- .../restapi/arrivals_and_departures_for_stop_handler_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/restapi/arrivals_and_departures_for_stop_handler_test.go b/internal/restapi/arrivals_and_departures_for_stop_handler_test.go index a1085e52..ce0eaca4 100644 --- a/internal/restapi/arrivals_and_departures_for_stop_handler_test.go +++ b/internal/restapi/arrivals_and_departures_for_stop_handler_test.go @@ -1232,6 +1232,7 @@ func TestArrivalsAndDeparturesForStop_VehicleWithNilID(t *testing.T) { api := createTestApiWithClock(t, mockClock) defer api.Shutdown() t.Cleanup(api.GtfsManager.MockResetRealTimeData) + t.Cleanup(api.GtfsManager.MockClearServiceIDsCache) ctx := context.Background() queries := api.GtfsManager.GtfsDB.Queries @@ -1280,6 +1281,10 @@ func TestArrivalsAndDeparturesForStop_VehicleWithNilID(t *testing.T) { }) require.NoError(t, err) + // Clear the service-IDs cache so the upcoming request sees the newly inserted + // calendar entry rather than a result cached by an earlier test in this package. + api.GtfsManager.MockClearServiceIDsCache() + _, err = queries.CreateTrip(ctx, gtfsdb.CreateTripParams{ ID: tripID, RouteID: routeID,