Skip to content

fix: add facility_type validation to prevent 500 on invalid input#3554

Open
Rahwulkumar wants to merge 1 commit intoohcnetwork:developfrom
Rahwulkumar:fix/facility-type-validation
Open

fix: add facility_type validation to prevent 500 on invalid input#3554
Rahwulkumar wants to merge 1 commit intoohcnetwork:developfrom
Rahwulkumar:fix/facility-type-validation

Conversation

@Rahwulkumar
Copy link

@Rahwulkumar Rahwulkumar commented Feb 27, 2026

Changes

Added a field_validator for facility_type in FacilityCreateSpec that validates the input value against REVERSE_REVERSE_FACILITY_TYPES before deserialization occurs.

This prevents a 500 Internal Server Error (KeyError) and returns a proper 400 Bad Request with a list of valid facility type options.

Fixes #3553

Summary by CodeRabbit

  • Bug Fixes
    • Added validation for facility type selection to prevent invalid entries. Users will now see a clear error message listing all valid facility type options when an incorrect value is submitted.

…Error

Invalid facility_type values like "private" caused an unhandled KeyError
in perform_extra_deserialization when looking up REVERSE_REVERSE_FACILITY_TYPES.

Added a field_validator that checks the value exists in the valid types
dictionary and raises a descriptive 400 validation error listing all
valid facility type options instead of crashing with a 500.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Rahwulkumar Rahwulkumar requested a review from a team as a code owner February 27, 2026 06:10
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b45422f and e7dc2e7.

📒 Files selected for processing (1)
  • care/emr/resources/facility/spec.py

📝 Walkthrough

Walkthrough

A field validator has been added to FacilityCreateSpec that validates facility_type against valid options in REVERSE_REVERSE_FACILITY_TYPES before processing. Invalid values now trigger validation errors early rather than causing downstream failures.

Changes

Cohort / File(s) Summary
Facility Type Validation
care/emr/resources/facility/spec.py
Added validate_facility_type() field validator to catch invalid facility type values early, preventing KeyError exceptions during dictionary lookup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete against the template. It lacks 'Proposed Changes' section structure, 'Architecture changes' clarity, and the merge checklist is entirely missing. Reorganize description to follow template: add 'Proposed Changes' heading with brief summary, confirm 'Associated Issue' section, and include the merge checklist with test/docs/lint confirmations.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding facility_type validation to prevent 500 errors on invalid input.
Linked Issues check ✅ Passed The code changes fully satisfy the linked issue #3553 by adding a field_validator that validates facility_type before dictionary lookup, preventing KeyError and returning 400 Bad Request.
Out of Scope Changes check ✅ Passed All changes are scoped to FacilityCreateSpec facility_type validation as required by issue #3553; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Invalid facility_type causes 500 Internal Server Error instead of 400 Bad Request

1 participant