Fix/status stops missing from ref stops when include schedule is false - #1353
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe handlers now derive referenced stops from schedule and status data separately. The route handler propagates stop lookup errors. An integration test verifies that closest and next status stops resolve when schedules are excluded. ChangesStatus stop references
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change restores status stop references when schedules are omitted and returns a server error instead of an empty reference set when stop lookup fails; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@JohnAkindipe Fix sonarcloud issues , follow what contributing.md says ; as i can there is duplications of code fix that |
…trips_for_location_handler
Code reviewFound 1 issue:
maglev/internal/restapi/trips_for_location_handler.go Lines 240 to 247 in 27b3ff4 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
aaronbrethorst
left a comment
There was a problem hiding this comment.
The diagnosis is right and the fix works — I confirmed the new test fails
against main and passes with the change. With includeSchedule=false there
are no schedule stop IDs at all, so status.closestStop/nextStop are the only
thing references.stops has to resolve from, and building the stops block
purely from schedule IDs left them dangling. Reusing trips-for-location's
existing helper instead of writing a second one is the right instinct.
What I'd like changed before this lands:
1. The now-shared helper is still in a handler-specific file, and its doc
comment no longer describes it.
stopsReferencedByEntries is called from both trips_for_route_handler.go and
trips_for_location_handler.go, but lives in the latter. CONTRIBUTING.md puts
reference-building helpers in internal/restapi/reference_utils.go, and commit
c00a305 moved the sibling stopReferences there for exactly this reason.
The comment is the bigger problem, because it now misleads:
stopsReferencedByEntries fetches the stops the response actually refers to:
those on each entry's schedule, plus the closest and next stops on its status.
The in-bounds stop set is deliberately not included — it is a candidate-trip
selection detail...
There are no entries in the signature any more, and "the in-bounds stop set" is
a trips-for-location concept that means nothing to a trips-for-route reader.
Please move the function to reference_utils.go, rewrite the comment for the
shared contract, and rename it — it takes schedules and statuses now, so
something like stopsReferencedBySchedulesAndStatuses says what it does.
2. The parallel-slice signature pushes duplication into both call sites.
Both handlers now repeat the same seven lines splitting entries into
schedules/statuses (trips_for_route_handler.go ~505, and
trips_for_location_handler.go ~118). That's the duplication @soumajitgh
flagged, and it's a consequence of the signature choice rather than an oversight
— two parallel slices that must stay index-aligned is a shape worth avoiding on
its own. Consider having the helper take the pairs directly (a small
{Schedule, Status} struct, or a variadic of them) so neither caller has to
build two lists in lockstep.
3. Please note the error-handling change in the description.
A GetStopsByIDs failure used to log a warning and degrade to an empty stops
block; it now returns a 500. I think that's the right change — CONTRIBUTING.md
is explicit that a failed query shouldn't be collapsed into a
looks-like-success response — but it's a behavior change beyond the stated scope
and a reviewer shouldn't have to discover it from the diff.
Small one: typo in the new test's comment — "the whole of whatreferences.stops".
One logistics note: I just merged #1360, which restructures buildTripReferences
in the same handler, so you'll need to merge main in and resolve. The two
changes are complementary — #1360 seeds routes from the stop references, this
one changes where the stops themselves come from — but the resolution isn't
purely mechanical, so give it a careful read. Happy to re-review promptly.
…-includeSchedule-false Resolve buildTripReferences restructure in trips-for-route-handler.go which was restructured in OneBusAway#1360
Relocate stopsReferencedByEntries to reference_utils.go since it is used by both trips_for_route_handler and trips_for_location_handler. Restructure it to accept a slice of structs containing trip schedule and status. Rename to stopsReferencedBySchedulesAndStatuses to reflect the change in its contract
|
|
Thanks — the requested changes have been addressed:
|



Fix dangling status stops in references.stops in trips-for-route
Closes #1338
Problem
trips-for-routebuildsreferences.stopsexclusively from the stop IDs collected out of each entry's schedule. That collection runs only inside theincludeSchedulebranch — in both the normal entry loop and the loop that appends DUPLICATED (extra-run) entries from the real-time feed — so when a request asks forincludeSchedule=false&includeStatus=true, no stop IDs are collected at all, while every entry's status still names aclosestStopandnextStop. Those IDs end up having no corresponding value inreferences.stopsFix
After both entry loops finish and before the reference is built, the handler now makes a single pass over the finished entries and records each non-nil status's
closestStopandnextStopinto the same stop-ID accumulator the schedule collection feeds.Testing
TestTripsForRouteHandler_StatusStopsAreReferenceddrives the handler withincludeSchedule=false&includeStatus=trueand asserts that every non-emptystatus.closestStop/nextStopacross all returned entries resolves inreferences.stops, while also asserting that no schedule information is returned. It fails on the pre-fix code and passes post-fix.Note
Previously, if
GetStopsByIDsreturned an error, the handler logged a warning and degradedreferences.Stopsto an empty slice; the response then continued and returned200 OKwithreferences.Stopstotally empty. This behavior contradicts CONTRIBUTING.md, on handling query failures. Now, ifGetStopsByIDsreturns an error the handler sends a500server error response instead.Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Tests