Skip to content

Commit

Permalink
Merge pull request #33 from internetofwater/comid-fail
Browse files Browse the repository at this point in the history
hotfix: comid key error
  • Loading branch information
gzt5142 authored Dec 20, 2024
2 parents d713e5c + 1930365 commit e59617f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ cython_debug/
secret.env
dist/
scratch.ipynb
scratch.json
3 changes: 2 additions & 1 deletion src/nldi/api/plugins/FlowlinePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _sqlalchemy_to_feature(self, item) -> Dict[str, Any]:

navigation = util.url_join(self.relative_url, feature.nhdplus_comid, "navigation")

return {
_response = {
"type": "Feature",
"properties": {
"identifier": str(feature.permanent_identifier),
Expand All @@ -164,3 +164,4 @@ def _sqlalchemy_to_feature(self, item) -> Dict[str, Any]:
},
"geometry": json.loads(geojson),
}
return _response
7 changes: 5 additions & 2 deletions src/nldi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,17 @@ def get_flowline_navigation(source_name=None, identifier=None, nav_mode=None):

try:
if source_name == "comid":
_id = NLDI_API.plugins["FlowlinePlugin"].get_by_id(identifier)
start_feature = NLDI_API.plugins["FlowlinePlugin"].get_by_id(identifier)
LOGGER.info("Found starting comid feature: %s", start_feature['properties'])
_id = start_feature['properties']['identifier']
start_comid = int(_id)
else:
feature = NLDI_API.plugins["FeaturePlugin"].get_by_id(
identifier, source_name
) # <<< ATTENTION: ``feature`` is instantiated here.
start_comid = int(feature["properties"]["comid"])
except (KeyError, ValueError):
except (KeyError, ValueError) as e:
LOGGER.error("Error getting COMID: %s", e)
return flask.Response(
status=http.HTTPStatus.INTERNAL_SERVER_ERROR,
response=f"Error getting COMID for {identifier=}, {source_name=}",
Expand Down

0 comments on commit e59617f

Please sign in to comment.