Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: comid key error #33

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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