fix: enabled removal of definitional field on product knowledge update
Proposed Changes
-
updated product knowledge updated spec
-
updated when definitional is None
Merge Checklist
- [ ] Tests added/fixed
- [ ] Update docs in
/docs - [ ] Linting Complete
- [ ] Any other necessary step
Only PR's with test cases included and passing lint and test pipelines will be reviewed
@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins
Summary by CodeRabbit
-
Bug Fixes
- Improved data consistency for product records: the product definition must now be explicitly provided (it may be set blank) and definition fields are reliably cleared when omitted during updates.
-
Tests
- API test payloads updated to include an explicit empty product definition to reflect the new behavior.
✏️ Tip: You can customize this high-level summary in your review settings.
📝 Walkthrough
Walkthrough
Removed the default value from definitional on BaseProductKnowledgeSpec (making the field required in the signature) and added a guard in ProductKnowledgeUpdateSpec.perform_extra_deserialization to set obj.definitional = None when self.definitional is None, ensuring explicit clearing on updates. Tests updated to include "definitional": None in generated payloads.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
Spec field signature care/emr/resources/inventory/product_knowledge/spec.py |
Changed BaseProductKnowledgeSpec.definitional from `ProductDefinitionSpec |
Deserialization guard logic care/emr/resources/inventory/product_knowledge/spec.py |
In ProductKnowledgeUpdateSpec.perform_extra_deserialization, added a guard: when self.definitional is None, set obj.definitional = None to explicitly clear the field during update deserialization. |
Tests payloads care/emr/tests/test_product_knowledge_api.py |
Added top-level "definitional": None to payloads in generate_product_knowledge_data and create_update_product_knowledge_data to match the updated spec shape. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
- Inspect all places that instantiate
BaseProductKnowledgeSpec(or subclasses) for reliance on the removed default and adjust callers if needed. - Verify runtime behavior with your validation library (pydantic/dataclass) to ensure optional-without-default doesn't break instantiation in common patterns.
- Confirm the update-path semantics: clearing
definitionalwhen omitted is intended and consistent with API expectations (tests were updated, but double-check other consumers).
Pre-merge checks and finishing touches
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The description is incomplete and vague. It lacks details about what was changed, why, and how the issue is resolved. The 'Associated Issue' section is missing entirely. | Provide a detailed explanation of the changes, include a link to the associated issue, and clearly explain how this fix enables removal of the definitional field. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title accurately describes the main change: enabling removal of the definitional field on product knowledge updates by removing the default value. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
nandkishorr/fix/product_knowledge_spec
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 @coderabbitai help to get the list of available commands and usage tips.
Codecov Report
:x: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 73.81%. Comparing base (ed21ebe) to head (bdf187a).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| .../emr/resources/inventory/product_knowledge/spec.py | 66.66% | 0 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #3348 +/- ##
===========================================
- Coverage 73.82% 73.81% -0.01%
===========================================
Files 435 435
Lines 19814 19816 +2
Branches 2153 2154 +1
===========================================
+ Hits 14627 14628 +1
Misses 4738 4738
- Partials 449 450 +1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.