Skip to content

Fix: Timeout HOT/OHSOME requests below gunicorn timeout#268

Open
susilnem wants to merge 2 commits into
developfrom
fix/timeout-issue
Open

Fix: Timeout HOT/OHSOME requests below gunicorn timeout#268
susilnem wants to merge 2 commits into
developfrom
fix/timeout-issue

Conversation

@susilnem

@susilnem susilnem commented Jul 1, 2026

Copy link
Copy Markdown
Member

Changes

  • Add Config.DEFAULT_EXTERNAL_API_TIMEOUT (kept below the 40s gunicorn --timeout) and use it instead of hardcoded 100/500s timeouts for HOT Tasking Manager, geojson URL, and OHSOME requests.

  • Add ValidateApiCallTimeoutError to distinguish OHSOME timeouts from other API failures, surfacing a clear "OHSOME request timed out. Please try again." message instead of a raw requests exception.

This PR doesn't introduce any:

  • temporary files, auto-generated files or secret keys
  • n+1 queries
  • flake8 issues
  • print
  • typos
  • unwanted comments

This PR contains valid:

  • tests
  • permission checks (tests here too)
  • translations

- Add Config.DEFAULT_EXTERNAL_API_TIMEOUT (kept below the 40s gunicorn
--timeout) and use it instead of hardcoded 100/500s timeouts for
HOT Tasking Manager, geojson URL, and OHSOME requests.

- Add ValidateApiCallTimeoutError to distinguish OHSOME timeouts from
other API failures, surfacing a clear "OHSOME request timed out.
Please try again." message instead of a raw requests exception.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 32.25806% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.43%. Comparing base (189901a) to head (be66785).

Files with missing lines Patch % Lines
project_types/validate/project.py 6.25% 15 Missing ⚠️
project_types/validate/api_calls.py 57.14% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #268      +/-   ##
===========================================
- Coverage    87.55%   87.43%   -0.12%     
===========================================
  Files          211      211              
  Lines        12819    12842      +23     
  Branches      1089     1089              
===========================================
+ Hits         11224    11229       +5     
- Misses        1196     1214      +18     
  Partials       399      399              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

return json


# fixme(frozenhelium): merge this function with `ohsome` and also add appropriate messages to raised exceptions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this comment?

logger.info("Target: %s", url)
logger.info("Filter: %s", ohsome_filter)

# fixme(frozenhelium): use httpx for proper timeout

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this comment? the default request timeout is not reliable

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should i migrate it to httpx?

Comment thread project_types/validate/api_calls.py Outdated
response = requests.post(url, data=data, timeout=timeout)
except requests.exceptions.Timeout as e:
logger.warning("ohsome element count request timed out")
raise ValidateApiCallTimeoutError("OHSOME request timed out. Please try again.") from e

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop "Please try again"
This was not directly triggered by the user

data["properties"] = properties
logger.info("Target: %s", url)
logger.info("Filter: %s", request["filter"])
# FIXME(tnagorra): Need to check what the timeout should be

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the FIXME comment. Also the timeout has changed from 100

feature_collection.model_dump_json(),
ohsome_filter,
)
except ValidateApiCallTimeoutError as e:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do wr need this except when we already have a generic except that does the same thing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the generic exception is used for all the Exception. Added new exception just for the Timeout exception! Should we just use the generic one?

feature_collection.model_dump_json(),
ohsome_filter,
)
except ValidateApiCallTimeoutError as e:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this except when we already have a generic except that does the same thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants