conveyal / r5

Developed to power Conveyal's web-based interface for scenario planning and land-use/transport accessibility analysis, R5 is our routing engine for multimodal (transit/bike/walk/car) networks with a particular focus on public transit
https://conveyal.com/learn
MIT License
272 stars 71 forks source link

Exclude modifications for regional analysis lookup #926

Closed trevorgerhardt closed 5 months ago

trevorgerhardt commented 5 months ago

This change adds a new helper method to pass a fields object to MongoMap#findByIdIfPermitted and utilizes that to exclude modifications while looking up a regional analysis to generate a scenarioJsonUrl.

This will prevent JacksonDBDecoder errors from occurring if custom modifications are used in a worker version that do not also exist in the server. Sample errors like:

java.lang.RuntimeException: IOException encountered while reading from a byte array input stream
at org.mongojack.internal.stream.JacksonDBDecoder.decode(JacksonDBDecoder.java:67)
at com.conveyal.analysis.persistence.MongoMap.findByIdIfPermitted(MongoMap.java:51)
abyrd commented 5 months ago

I just tried out replacing DBProjection.exclude("request.scenario.modifications") with DBProjection.include("bundleId", "scenarioId", "accessGroup" to grab only the fields necessary to return the API response. This does work... almost. But the field regionalAnalysis.request.scenarioId is different than regionalAnalysis.scenarioId in the baseline scenario case (UUID versus the string "baseline" respectively). Fetching regionalAnalysis.request.scenarioId means fetching regionalAnalysis.request which runs into other problems with type fields and quickly becomes more trouble than it's worth. The other underlying problem to note here is that we have multiple ways to reference the baseline scenario as a string and mix them together in a single object.