From e4614bb6ac54927158a883daef49060e29ba28dd Mon Sep 17 00:00:00 2001 From: Andrew Byrd Date: Thu, 3 Oct 2024 12:27:29 -0400 Subject: [PATCH] clarify why unknown field names are tolerated --- .../com/conveyal/analysis/controllers/BundleController.java | 5 +++-- src/main/java/com/conveyal/analysis/models/Bundle.java | 2 +- .../java/com/conveyal/r5/transit/TransportNetworkCache.java | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/conveyal/analysis/controllers/BundleController.java b/src/main/java/com/conveyal/analysis/controllers/BundleController.java index dc3034583..decd74a2c 100644 --- a/src/main/java/com/conveyal/analysis/controllers/BundleController.java +++ b/src/main/java/com/conveyal/analysis/controllers/BundleController.java @@ -134,8 +134,9 @@ private Bundle create (Request req, Response res) { bundle.totalFeeds = bundleWithFeed.totalFeeds; } if (files.get("config") != null) { - // For validation, rather than reading as freeform JSON, deserialize into a model class instance. - // However, only the instance fields specifying things other than OSM and GTFS IDs will be retained. + // Validation by deserializing into a model class instance. Unknown fields are ignored to + // allow sending config to custom or experimental workers with features unknown to the backend. + // The fields specifying OSM and GTFS IDs are not expected here. They will be ignored and overwritten. String configString = files.get("config").get(0).getString(); bundle.config = JsonUtil.objectMapper.readValue(configString, TransportNetworkConfig.class); } diff --git a/src/main/java/com/conveyal/analysis/models/Bundle.java b/src/main/java/com/conveyal/analysis/models/Bundle.java index 44cea922b..4d5bef3e6 100644 --- a/src/main/java/com/conveyal/analysis/models/Bundle.java +++ b/src/main/java/com/conveyal/analysis/models/Bundle.java @@ -48,7 +48,7 @@ public class Bundle extends Model implements Cloneable { public int feedsComplete; public int totalFeeds; - // The definitive TransportNetworkConfig is a JSON file stored alonside the feeds in file storage. It is + // The definitive TransportNetworkConfig is a JSON file stored alongside the feeds in file storage. It is // duplicated here to record any additional user-specified options that were supplied when the bundle was created. // It may contain redundant copies of information stored in the outer level Bundle such as OSM and GTFS feed IDs. public TransportNetworkConfig config; diff --git a/src/main/java/com/conveyal/r5/transit/TransportNetworkCache.java b/src/main/java/com/conveyal/r5/transit/TransportNetworkCache.java index b7f1f1d8f..6a0c291ab 100644 --- a/src/main/java/com/conveyal/r5/transit/TransportNetworkCache.java +++ b/src/main/java/com/conveyal/r5/transit/TransportNetworkCache.java @@ -168,6 +168,8 @@ private TransportNetworkConfig loadNetworkConfig (String networkId) { File configFile = fileStorage.getFile(configFileKey); try { // Use lenient mapper to mimic behavior in objectFromRequestBody. + // A single network configuration file might be used across several worker versions. Unknown field names + // may be present for other worker versions unknown to this one. So we can't strictly validate field names. return JsonUtilities.lenientObjectMapper.readValue(configFile, TransportNetworkConfig.class); } catch (IOException e) { throw new RuntimeException("Error reading TransportNetworkConfig. Does it contain new unrecognized fields?", e);