Skip to content

feat: moving the aiworkflowview from regular django view to drf apiview#217

Open
felipemontoya wants to merge 1 commit intoopenedx:mainfrom
eduNEXT:fmo/apiview
Open

feat: moving the aiworkflowview from regular django view to drf apiview#217
felipemontoya wants to merge 1 commit intoopenedx:mainfrom
eduNEXT:fmo/apiview

Conversation

@felipemontoya
Copy link
Copy Markdown
Member

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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels May 8, 2026
@openedx-webhooks
Copy link
Copy Markdown

Thanks for the pull request, @felipemontoya!

This repository is currently maintained by @felipemontoya.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AIGenericWorkflowView to DRF APIView and switch request body parsing to request.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.

Comment on lines +32 to +36
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"""
Comment on lines 104 to 112
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
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.14%. Comparing base (972f2fe) to head (02509df).

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     
Flag Coverage Δ
unittests 95.14% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants