Skip to content

[ENG-336] fix: Swagger failed to load api definitons#3648

Merged
vigneshhari merged 1 commit into
developfrom
ENG-336-swagger-failed-to-load-api-definitons
May 19, 2026
Merged

[ENG-336] fix: Swagger failed to load api definitons#3648
vigneshhari merged 1 commit into
developfrom
ENG-336-swagger-failed-to-load-api-definitons

Conversation

@nandkishorr
Copy link
Copy Markdown
Contributor

@nandkishorr nandkishorr commented May 18, 2026

Proposed Changes

  • Added a request check wrapper in plug config authz check

Associated Issue

  • Swagger api schema failed to load.

Architecture changes

  • Remove this section if not used

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 API stability and reliability with enhanced defensive checks in the request authentication process. This prevents potential service failures when handling certain types of requests, ensuring more robust operation.

Review Change Stack

@nandkishorr nandkishorr self-assigned this May 18, 2026
@nandkishorr nandkishorr requested a review from a team as a code owner May 18, 2026 18:30
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 33ac3ba9-4fb2-43fd-8e30-2d93f51b714e

📥 Commits

Reviewing files that changed from the base of the PR and between 96f0ce2 and 919d8e0.

📒 Files selected for processing (1)
  • care/users/api/viewsets/plug_config.py

📝 Walkthrough

Walkthrough

The PR adds a defensive guard clause to PlugConfigViewset.get_authenticators(), checking for the existence of self.request via getattr() before accessing its method attribute. This prevents AttributeError when the method is invoked in contexts where request is not available.

Changes

Request existence guard in plug config authenticator

Layer / File(s) Summary
Defensive request existence check in authenticator
care/users/api/viewsets/plug_config.py
The get_authenticators() method now safely verifies self.request exists via getattr() before evaluating its HTTP method, preventing AttributeError when the request attribute is missing.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • ohcnetwork/care#3642: Also modifies PlugConfigViewset.get_authenticators() GET handling logic in the same file.

Suggested reviewers

  • vigneshhari
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly references the main fix: addressing a Swagger API schema loading issue by adding a request check in plug config authentication.
Description check ✅ Passed The description covers proposed changes and associated issue, though it lacks detail on what specifically causes the Swagger failure and how the fix resolves it.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ENG-336-swagger-failed-to-load-api-definitons

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.

@nandkishorr nandkishorr changed the title [ENG-336 ] fix: Swagger failed to load api definitons [ENG-336] fix: Swagger failed to load api definitons May 18, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 18, 2026

Greptile Summary

Fixes a Swagger/OpenAPI schema generation failure caused by get_authenticators() accessing self.request.method when request is not yet set on the viewset during DRF's schema introspection phase.

  • Wraps the self.request access with getattr(self, \"request\", None) so that schema generation (which calls get_authenticators() without a live request) falls through to the default authenticators rather than raising AttributeError.
  • Also simplifies self.request.method in [\"GET\"] to self.request.method == \"GET\" as a minor style improvement.

Confidence Score: 5/5

Safe to merge — single-line guard that fixes a Swagger crash without altering runtime authentication behavior.

The change is minimal and precisely targeted at the known failure mode: DRF's schema generator calls get_authenticators() on a viewset instance that has not yet had initialize_request() called, so self.request doesn't exist. The getattr guard is the canonical fix. Runtime behavior for real API requests is unchanged because self.request is always set by the time an actual HTTP request is processed.

No files require special attention.

Important Files Changed

Filename Overview
care/users/api/viewsets/plug_config.py Guards get_authenticators() against missing request attribute during DRF schema introspection, fixing Swagger load failure

Reviews (1): Last reviewed commit: "fix:added request wrapper" | Re-trigger Greptile

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.44%. Comparing base (96f0ce2) to head (919d8e0).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3648      +/-   ##
===========================================
- Coverage    75.46%   75.44%   -0.02%     
===========================================
  Files          479      479              
  Lines        22984    22984              
  Branches      2375     2375              
===========================================
- Hits         17344    17341       -3     
- Misses        5068     5069       +1     
- Partials       572      574       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vigneshhari vigneshhari merged commit 5b01692 into develop May 19, 2026
12 of 13 checks passed
@vigneshhari vigneshhari deleted the ENG-336-swagger-failed-to-load-api-definitons branch May 19, 2026 05:04
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