Skip to content

fix: dispatch() error handler returns exc instead of response#8933

Open
MinitJain wants to merge 1 commit intomakeplane:previewfrom
MinitJain:fix/dispatch-exception-return
Open

fix: dispatch() error handler returns exc instead of response#8933
MinitJain wants to merge 1 commit intomakeplane:previewfrom
MinitJain:fix/dispatch-exception-return

Conversation

@MinitJain
Copy link
Copy Markdown

@MinitJain MinitJain commented Apr 26, 2026

Description

Fixes #8932

In all four base view files, dispatch() calls self.handle_exception(exc) to build a proper HTTP response but then returns the raw Python exception object (exc) instead of the response variable it just built.

# Before (wrong)
except Exception as exc:
    response = self.handle_exception(exc)
    return exc

# After (correct)
except Exception as exc:
    response = self.handle_exception(exc)
    return response

Six lines changed across four files — nothing else.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Test Scenarios

  1. Hit a non-existent resource endpoint — should return {"error": "The required object does not exist."} with status 404
  2. Send invalid data to a write endpoint — should return {"error": "Please provide valid detail"} with status 400
  3. Confirm normal (non-error) responses are unaffected

References

Closes #8932

Summary by CodeRabbit

  • Bug Fixes
    • Fixed exception handling across API modules to ensure error responses are properly formatted as HTTP responses with appropriate status codes and error messages, rather than returning raw exception objects.
    • Improves consistency and reliability of error handling across all API endpoints.

All base view dispatch() methods were calling handle_exception(exc) to
build a proper HTTP response but then returning the raw exception object
instead of the computed response variable. Fix applied across all four
base view files (app, api, license, space).
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9c480b91-cf2c-4fb0-ba5e-7af9b610b40a

📥 Commits

Reviewing files that changed from the base of the PR and between 32fb88a and 2e761c5.

📒 Files selected for processing (4)
  • apps/api/plane/api/views/base.py
  • apps/api/plane/app/views/base.py
  • apps/api/plane/license/api/views/base.py
  • apps/api/plane/space/views/base.py

📝 Walkthrough

Walkthrough

This pull request fixes a bug across four base view files where exception handlers were returning the raw exception object instead of the properly formatted HTTP response. The fix ensures all views consistently return DRF-compliant error responses with appropriate status codes.

Changes

Cohort / File(s) Summary
Dual Dispatch Exception Handling
apps/api/plane/app/views/base.py, apps/api/plane/space/views/base.py
Updated both BaseViewSet.dispatch and BaseAPIView.dispatch to return self.handle_exception(exc) instead of the raw exception object in exception handlers.
Single Dispatch Exception Handling
apps/api/plane/api/views/base.py, apps/api/plane/license/api/views/base.py
Updated BaseAPIView.dispatch to return self.handle_exception(exc) instead of the raw exception object in exception handlers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A bug was caught in dispatch's hand,
Returning exceptions across the land,
But now we return what was meant to be—
A proper response, safe and free! ✨

🚥 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 and concisely describes the main bug fix: dispatch() error handlers returning the exception object instead of the proper HTTP response.
Description check ✅ Passed The description includes all required template sections: detailed explanation with before/after code, Type of Change marked as bug fix, Test Scenarios defined, and issue reference provided.
Linked Issues check ✅ Passed All code changes directly address issue #8932 by fixing the exception return path in all four affected base view files, replacing 'return exc' with 'return response' as required.
Out of Scope Changes check ✅ Passed All six line changes across four files are directly scoped to fixing the identified bug; no unrelated modifications or refactoring are present.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@MinitJain MinitJain changed the title fix: dispatch() returns exc instead of response in error handlers fix: dispatch() error handler returns exc instead of response Apr 26, 2026
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.

[bug]: dispatch() returns exception object instead of HTTP response on error

1 participant