Skip to content

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

Merged
felipemontoya merged 1 commit into
openedx:mainfrom
eduNEXT:fmo/apiview
Jun 19, 2026
Merged

feat: moving the aiworkflowview from regular django view to drf apiview#217
felipemontoya merged 1 commit into
openedx: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

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.33%. Comparing base (39f61b0) to head (c4b4d75).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
+ Coverage   95.32%   95.33%   +0.01%     
==========================================
  Files          69       69              
  Lines        8086     8088       +2     
  Branches      432      431       -1     
==========================================
+ Hits         7708     7711       +3     
  Misses        283      283              
+ Partials       95       94       -1     
Flag Coverage Δ
unittests 95.33% <ø> (+0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions May 14, 2026
@felipemontoya felipemontoya requested a review from Copilot June 18, 2026 19:43
@felipemontoya

Copy link
Copy Markdown
Member Author

@Henrrypg this is a minor fix, but I used some of my cc time to rebase and and make it pass tests again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread backend/tests/test_api.py
Comment thread backend/openedx_ai_extensions/api/v1/workflows/views.py
Comment thread backend/openedx_ai_extensions/api/v1/workflows/views.py Outdated

@Henrrypg Henrrypg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

fix: addressing comments from the PR

fix: add tests to keep coverage over limit
@felipemontoya felipemontoya merged commit 64576dc into openedx:main Jun 19, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting on Author to Done in Contributions Jun 19, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

5 participants