fix: handle malformed api_constraints without crashing endpoint (#273)#285
fix: handle malformed api_constraints without crashing endpoint (#273)#285Gokul-social wants to merge 6 commits intoopenml:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds module-level logging and a new helper 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
parse_api_constraints, you currently only accept plaindictinstances; if upstream ever passes aMapping(e.g.dict-like) object it will be treated as unsupported, so consider loosening the type check tocollections.abc.Mappingto make the helper more robust to different ORM or serialization layers. - The
test_valid_constraint_no_warningassertionlen(caplog.records) == 0can be brittle if any other logger emits during the test run; it would be safer to assert that there are no records from the specific logger or containing theapi_constraints:prefix instead of enforcing an absolutely empty log.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `parse_api_constraints`, you currently only accept plain `dict` instances; if upstream ever passes a `Mapping` (e.g. `dict`-like) object it will be treated as unsupported, so consider loosening the type check to `collections.abc.Mapping` to make the helper more robust to different ORM or serialization layers.
- The `test_valid_constraint_no_warning` assertion `len(caplog.records) == 0` can be brittle if any other logger emits during the test run; it would be safer to assert that there are no records from the specific logger or containing the `api_constraints:` prefix instead of enforcing an absolutely empty log.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
Hardens the /tasktype/{task_type_id} endpoint so malformed or inconsistent api_constraints data no longer causes 500s, aligning behavior with issue #273.
Changes:
- Added
parse_api_constraintshelper to defensively parseapi_constraintsand safely extractdata_type. - Updated task type response construction to include
input[].data_typeonly when valid. - Added unit tests covering valid/malformed inputs and logging behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/routers/openml/tasktype.py |
Introduces defensive parsing + logging and uses it when building the /tasktype/{id} response. |
tests/routers/openml/test_parse_api_constraints.py |
Adds unit tests for parsing outcomes and emitted log levels/messages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
for more information, see https://pre-commit.ci
Summary
Hardens the
/tasktype/{task_type_id}endpoint against inconsistentapi_constraintsdata. Fixes #273.The Problem
The existing implementation was fragile, relying on strict
json.loads()and direct key access. This led to unnecessary 500 errors when encountering:dicttypes in the persistence layer.data_typekeys, triggering unhandledKeyErrors.The Solution
I've introduced a defensive
parse_api_constraintshelper to act as a buffer between the DB and the response..get()with strict type-checking fordata_type. If a value is invalid, it is omitted from the output rather than crashing the request.WARNINGfor structural failures,DEBUGfor missing data) prefixed withapi_constraints:to help us audit bad data in production.Testing
Comprehensive unit tests added to cover: