feat: moving the aiworkflowview from regular django view to drf apiview#217
feat: moving the aiworkflowview from regular django view to drf apiview#217felipemontoya wants to merge 1 commit intoopenedx:mainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for the pull request, @felipemontoya! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
There was a problem hiding this comment.
Pull request overview
This PR migrates the workflows endpoint (AIGenericWorkflowView) from a Django View protected by login_required redirects to a DRF APIView protected by IsAuthenticated, aligning unauthenticated behavior with API expectations (403 instead of 302 redirect).
Changes:
- Convert
AIGenericWorkflowViewto DRFAPIViewand switch request body parsing torequest.data. - Update API authentication test expectations for unauthenticated access (302 → 403).
- Improve operational logging in the session-based orchestrator and expand AI error mapping for LiteLLM
NotFoundError.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
backend/openedx_ai_extensions/api/v1/workflows/views.py |
Migrates workflow view to DRF APIView, uses IsAuthenticated, and reads payload via request.data. |
backend/tests/test_api.py |
Adjusts unauthenticated workflows endpoint test expectation to DRF-style 403. |
backend/openedx_ai_extensions/decorators.py |
Adds LiteLLM NotFoundError mapping to standardized error responses. |
backend/openedx_ai_extensions/workflows/orchestrators/session_based_orchestrator.py |
Improves exception logging to include stack traces and structured logging args. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| NotFoundError: { | ||
| "code": "llm_config_error", | ||
| "message": "The AI service is misconfigured. Please check the LLM settings.", | ||
| "status": status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
| }, |
|
|
||
| @method_decorator(handle_ai_errors) | ||
| def post(self, request): | ||
| """Common handler for GET and POST requests""" |
| except Exception as e: | ||
| logger.error(f"Task {task_id}: Error executing {action} for session {session_id}: {str(e)}") | ||
| logger.error( | ||
| "Task %s: Error executing %s for session %s: %s", | ||
| task_id, action, session_id, str(e), | ||
| exc_info=True, | ||
| ) | ||
| session.metadata['task_status'] = 'error' | ||
| session.metadata['task_error'] = str(e) | ||
| session.save(update_fields=['metadata']) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #217 +/- ##
=======================================
Coverage 95.13% 95.14%
=======================================
Files 67 67
Lines 7322 7312 -10
Branches 387 386 -1
=======================================
- Hits 6966 6957 -9
Misses 267 267
+ Partials 89 88 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Migrating AIGenericWorkflowView from Django's login_required to DRF's IsAuthenticated
This is a minor upgrade to avoid having unauthenticated calls due to the mismatch in the response the API expects and the management that login_required gives