jamespfennell / transiter

Web service for transit data
https://demo.transiter.dev
MIT License
59 stars 7 forks source link

Exclude trips with no arrival or departure time set #86

Closed cedarbaum closed 2 years ago

cedarbaum commented 2 years ago

There appear to be some cases where a Trip has neither arrival nor departure times set. This causes the stops/{STOP_ID} endpoint to fail with the error below.

I am not sure if this is a feed corruption issue or expected behavior in some cases, but in either case, filtering out such trips seems to be the correct behavior.

❯ curl -X GET $TRANSITER_SERVER'/systems/us-ny-subway/stops/A31-L01'
{
  "type": "UNEXPECTED_ERROR",
  "code": "T011",
  "message": "There was an unexpected error. This generally indicates a bug in Transiter",
  "parameters": {
    "type": "AttributeError",
    "message": "'NoneType' object has no attribute 'timestamp'",
    "stack_trace": [
      "Traceback (most recent call last):",
      "  File \"/usr/local/lib/python3.8/site-packages/flask/app.py\", line 1950, in full_dispatch_request",
      "    rv = self.dispatch_request()",
      "  File \"/usr/local/lib/python3.8/site-packages/flask/app.py\", line 1936, in dispatch_request",
      "    return self.view_functions[rule.endpoint](**req.view_args)",
      "  File \"<decorator-gen-52>\", line 2, in get_in_system_by_id",
      "  File \"/usr/local/lib/python3.8/site-packages/transiter/http/httpmanager.py\", line 136, in _json_response",
      "    response = func(*args, **kwargs)",
      "  File \"/usr/local/lib/python3.8/site-packages/transiter/http/endpoints/stopendpoints.py\", line 111, in get_in_system_by_id",
      "    return stopservice.get_in_system_by_id(",
      "  File \"<decorator-gen-48>\", line 2, in get_in_system_by_id",
      "  File \"/usr/local/lib/python3.8/site-packages/transiter/db/dbconnection.py\", line 106, in unit_of_work",
      "    return func(*args, **kw)",
      "  File \"/usr/local/lib/python3.8/site-packages/transiter/services/stopservice.py\", line 153, in get_in_system_by_id",
      "    if stop_time_filter.remove(trip_stop_time, direction):",
      "  File \"/usr/local/lib/python3.8/site-packages/transiter/services/stopservice.py\", line 177, in remove",
      "    result = self._remove_helper(trip_stop_time, direction)",
      "  File \"/usr/local/lib/python3.8/site-packages/transiter/services/stopservice.py\", line 185, in _remove_helper",
      "    trip_time = trip_stop_time.get_time().timestamp()",
      "AttributeError: 'NoneType' object has no attribute 'timestamp'"
    ]
  }
}
jamespfennell commented 2 years ago

Awesome catch!

Yeah feed corruption could definitely create something like that - but corrupt data is everywhere in GTFS land so it definitely should still work.

jamespfennell commented 2 years ago

The tests are failing because Python builds are not reproducible in general. I've had a bunch of problems recently with transitive dependencies changing randomly...