Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leoaulasneo98
Copy link

@leoaulasneo98 leoaulasneo98 commented Feb 5, 2025

FC-73 Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System

⚠️ Important: This PR depends on submission structure changes implemented in edx-platform repository. Please ensure those changes are deployed before merging this PR.

Description

This pull request introduces the SubmissionQueueRecord model as part of a gradual migration of the Open edX submission queueing system (xqueue) towards a more robust and maintainable submission processing system.

Motivation

The current xqueue system requires a strategic update to:

  • Provide seamless transition for existing services (xwatcher)
  • Enhance submission state management
  • Optimize processing and tracking of submission tasks

Key Improvements

Model Enhancements

  • Introduced SubmissionQueueRecord with:
  • Explicit state management
  • Consolidated timestamp tracking (status_time)
  • Atomic state transitions
  • Support for dynamic field assignment

New Fields Added

  • queue_name: Identifies processing queue
  • status: Current submission queue state
  • status_time: Unified timestamp for state tracking
  • pullkey: Submission processing tracking key
  • grader_file_name: Grading file metadata
  • grader_reply: Grader response storage
  • points_possible: Maximum possible points

Queue Processing Improvements

  • Introduced SubmissionQueueManager for queue query processing
  • Implemented state transition validation
  • Optimized database indexes for queue operations

Technical Details

State Management

  • Defined STATUS_CHOICES
  • Implemented VALID_TRANSITIONS
  • Created transaction-safe update_status() method

Error Handling

  • Added custom SubmissionQueueCanNotBeEmptyError
  • Improved field validation
  • Safer dictionary access using event_data.get()

Testing Strategy

Comprehensive test coverage includes:

  • Basic model functionality
  • State transition validation
  • Error handling
  • Integration with existing submission system

Next Phases

Planned Developments

  • Integrate with new edX submission services to meet xwatcher requirements
  • Develop robust documentation as the implementation evolves
  • Prepare for potential future enhancements in file handling and processing

Open edX Compliance

Adheres to Open edX standards:

  • Modular and extensible design
  • Comprehensive error handling
  • Extensive test coverage

Performance Considerations

  • Optimized database indexing
  • Efficient state transition mechanism
  • Minimal processing overhead

BREAKING CHANGES: None. Designed to be fully compatible with existing systems.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Feb 5, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Feb 5, 2025

Thanks for the pull request, @leoaulasneo98!

This repository is currently maintained by @openedx/committers-edx-submissions.

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.


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.

@mphilbrick211
Copy link

@leoaulasneo98! Looks like you're contributing on behalf of Aulasneo -- if you haven't already, please have your manager reach out to [email protected] to have you added to our existing entity CLA. Thanks!

@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Feb 6, 2025
@sarina sarina added the FC Relates to an Axim Funded Contribution project label Feb 7, 2025
@sarina
Copy link
Contributor

sarina commented Feb 7, 2025

@leoaulasneo98 could you ensure you get tests passing on this PR?

@sarina sarina changed the title Xqu 15 add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) Feb 7, 2025
@leoaulasneo98
Copy link
Author

Sure Sarina already checked it.

@leoaulasneo98 leoaulasneo98 marked this pull request as draft February 10, 2025 18:53
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.54%. Comparing base (639e196) to head (f1d19f4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #283      +/-   ##
==========================================
+ Coverage   93.53%   94.54%   +1.01%     
==========================================
  Files          18       18              
  Lines        1995     2310     +315     
  Branches       90       98       +8     
==========================================
+ Hits         1866     2184     +318     
+ Misses        118      115       -3     
  Partials       11       11              
Flag Coverage Δ
unittests 94.54% <100.00%> (+1.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.

@mphilbrick211 mphilbrick211 removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Feb 11, 2025
@sarina
Copy link
Contributor

sarina commented Feb 12, 2025

@leoaulasneo98 could I ask that you comment on your PR rather than via email? The alerts I'm getting are kind of hard to follow.

@leoaulasneo98
Copy link
Author

@leoaulasneo98 could I ask that you comment on your PR rather than via email? The alerts I'm getting are kind of hard to follow.

Hello Sarina, yes I apologize. I received the alert by email and responded there and then I realized it was a comment in the PR.

@e0d e0d changed the title FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) Feb 13, 2025
@e0d e0d changed the title FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) Feb 13, 2025
@e0d e0d changed the title FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) ! Feb 13, 2025
@e0d e0d changed the title FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) ! FC-73 XQueue add fields to submission model (Feature: SubmissionQueueRecord - Gradual Migration from Xqueue System) Feb 13, 2025
@leoaulasneo98 leoaulasneo98 force-pushed the XQU-15-add-fields-to-submission-model branch 3 times, most recently from 0682d7a to 731ce57 Compare February 20, 2025 14:19
This commit updates the XQueue Migration ADR to be more accessible while
maintaining critical technical information. Key changes include:

- Streamline context section focusing on core system limitations
- Reorganize decision section with clearer structure
- Add implementation approach section for gradual migration
- Maintain technical details in consequences section
- Keep all original references for further documentation

Part of the XQueue migration initiative.

refactor: squashed migrations

- Delete all migrations
- Run again makemigrations
- Test in secure environment

refactor: change submission queue record name functionalities

- Change SubmissionQueueManager to ExternalGraderDetailManager
- Change create_submission_queue_record to create_external_grader_detail
- Change validation to queue name in create_submission
- Remove unnecessary test to check queue name error

refactor(submissions): Rename SubmissionQueueRecord to ExternalGraderDetail

- Rename model SubmissionQueueRecord to ExternalGraderDetail
- Update all references in Python files
- Create Django migration for model renaming
- Update related imports and references

feat: add ADR for SubmissionQueueRecord migration from XQueue

Add Architecture Decision Record (ADR) documenting the design and implementation
of the SubmissionQueueRecord model as part of the gradual migration from XQueue
to edx-submissions.

This ADR covers:
- Context of current XQueue architecture
- Technical details of new model implementation in edx submissions
- Migration and compatibility considerations
- Impact analysis and consequences

feat: add architecture decisions to documentation

- Create new decisions folder
- Configurate in index.rst

test: add validation tests for SubmissionQueueRecord state transitions

- Add test_clean_invalid_transitions to verify error cases:
  - pending -> retired (not allowed)
  - pending -> invalid_status
  - pulled -> pending (not allowed)
  - failed -> retired (not allowed)
- Enhance test_clean_valid_transitions with proper assertions

This improves test coverage for state transition validations.

fix: change validation SubmissionQueueRecord clean method

- Add an optional status can_transition_to
- Implement old status in clean method

This resolves a bug in the implementation of transition validation when using the clean method.

fix: remove try except in test_clean_new_instance

- Remove unnecessary try/except in test_clean_new_instance
- Add validations when new queue record call clean method
- Extend coverage measure in test_models

test: Add tests to extend coverage for SubmissionQueueRecord model

- Status transition rules
- Failure count tracking
- Queue length calculations
- Submission retrieval logic

The new tests improve the robustness of the submissions app by covering.

docs: Improve create_submission docstring formatting

- Fix Sphinx documentation warnings
- Correct formatting and indentation issues
- Clarify parameter and return value descriptions

Resolves documentation build warnings related to:
- Inline strong start-string without end-string
- Unexpected indentation

fix: correct docstring formatting in create_submission

- Add proper indentation and blank lines between sections
- Fix example code block formatting
- Replace >>> with ... for continued lines in example
- Ensure consistent spacing throughout docstring

This resolves the ReadTheDocs build failure and docstring formatting warning.

fix: code style and quality improvements

- Fix pylint warnings:
  - Remove protected access warnings in test files
  - Remove pointless string statements
  - Add missing final newlines
- Fix isort import ordering in:
  - api.py
  - test_models.py
  - test_api.py
- Fix pycodestyle issues:
  - Remove extra blank lines
  - Fix operator spacing
  - Add proper spacing before inline comments
  - Fix long lines in migration files
  - Fix line spacing in test files
- Fix docstring formatting in api.py create_submission method

Testing:
make test_quality passes without warnings

feat: add grading metadata fields to submission queue record

- Add grader_file_name CharField (128 chars max) with empty default
- Add points_possible PositiveIntegerField with default value of 1
- Update create_submission_queue_record to handle new fields

fix: Remove duplicate nested create_submission function definition

- Removes the redundant nested function definition

feat: add nullable pullkey and grader_reply to Submission model

feat(SubmissionQueueRecord): add pullkey and grader_reply fields

- Add pullkey CharField(128) for tracking submission processing key
- Add grader_reply TextField to store grader's response
- Fields support queue processing and feedback management to xwatcher

test: add comprehensive tests for Submission and SubmissionQueueRecord models

Add missing test suite for Submission model and add new tests for SubmissionQueueRecord:

Submission model tests (previously non-existent):
- Basic model functionality (creation, retrieval)
- String and repr representations
- Large answer handling
- Field mutability behavior
- Submission ordering
- Soft deletion mechanism
- JSON serialization of answers

SubmissionQueueRecord model tests:
- Default status and initialization
- Valid and invalid status transitions
- Failure count tracking
- Record processability logic
- Queue name validation
- One-to-one relationship with Submission
- Status time updates

Updates:
- Fix repr test to handle UUID and string conversions
- Document actual mutability behavior
- Add validation for large answers
- Ensure proper status transitions and timing
- Verify queue processing logic

The test suite ensures both models work correctly together
and maintain data integrity through their lifecycle.
Note: This commit adds the first test coverage for the Submission model,
which previously lacked any automated testing.

refactor: update submission queue record tests

- Update test cases to use new public create_submission_queue_record function
- Update assertions to use SubmissionQueueCanNotBeEmptyError instead of ValueError
- Adjust test function parameters to match new interface (queue_name and files)
- Add new test cases for empty queue_name validation

The changes ensure test coverage for:
- Direct queue record creation with valid and invalid inputs
- Integration with create_submission function
- Multiple submission queue records
- Error handling scenarios

fix: add blank line in models

- This fixed the pylint warning

feat(error): add SubmissionQueueCanNotBeEmptyError class error

- This class is to is raised when queue name is empty

fix: improve submission queue record validation

- Update condition for creating submission queue record to properly check for queue_name
- Use `event_data.get()` for safer dictionary access
- Change ValueError to SubmissionQueueCanNotBeEmptyError for more specific error handling
- Add proper validation in parent function to prevent None access errors

The changes ensure that:
1. Queue name validation is more robust
2. Error handling is more specific and clear
3. Null checks are properly implemented

Test coverage remains unchanged.

refactor(submission): simplify queue record creation with explicit field

- Replace dynamic unpacking of event_data with explicit queue_name field
- Remove unnecessary field expansion to improve code clarity and maintainability

test: add queue record unit and integration tests

- Add unit tests for _create_submission_queue_record helper function
  - Basic queue record creation
  - Queue name validation
  - Database error handling

- Add integration tests with create_submission
  - Queue record creation via submission creation
  - Multiple queue records with same name
  - Error handling with missing queue name
  - Database error integration testing

Organized tests into clearly separated unit and integration sections
for better maintainability and clarity.

feat: add submission queue record functionality

- Add _create_submission_queue_record helper function to handle queue record creation
- Modify create_submission to accept event_data as kwargs
- Update documentation to reflect new parameters and functionality
- Allow dynamic field assignment using event_data kwargs in queue record creation

The main changes:
- Added ability to create SubmissionQueueRecord with dynamic fields
- Improved error handling for queue record creation
- Made event_data more flexible using kwargs pattern
- Maintained backwards compatibility with existing submission creation

feat(submissions): add SubmissionQueueRecord model

- Add SubmissionQueueManager to process queries
- Replace multiple timestamps with a single status_time field
- Introduce explicit state machine for submission processing
- Add atomic state transitions with validation
- Optimize database indexes for queue operations

Key changes:
- Add STATUS_CHOICES and VALID_TRANSITIONS for state management
- Consolidate pull_time, push_time, return_time into status_time
- Add transaction-safe update_status() method
- Improve queue manager with safer submission retrieval
- Add validation for state transitions
- Optimize indexes for common query patterns

The changes maintain backwards compatibility with existing queue
processing while providing a more robust and maintainable approach
to state management.
@leoaulasneo98 leoaulasneo98 force-pushed the XQU-15-add-fields-to-submission-model branch from 527d0c2 to f1d19f4 Compare February 21, 2025 13:53
@leoaulasneo98 leoaulasneo98 marked this pull request as ready for review February 21, 2025 14:51
@leoaulasneo98
Copy link
Author

Hi @ormsbee, hi @sarina, this PR is ready for code review, please leave us any comments, observations and corrections you have, we are waiting.

@sarina
Copy link
Contributor

sarina commented Feb 21, 2025

@leoaulasneo98 - did your team review this ? I don't see any comments from anyone on the PR

@angonz
Copy link

angonz commented Feb 21, 2025

@sarina They have my go-ahead.

@ormsbee
Copy link

ormsbee commented Feb 24, 2025

Thanks folks! I'll review by end of day Wednesday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U
Projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

6 participants