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

update remote_autotest_settings_id validation #7393

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

donny-wong
Copy link
Contributor

@donny-wong donny-wong commented Jan 27, 2025

Proposed Changes

Currently, the remote_autotest_settings_id validation on assignment_properties model is set to being unique. This would cause the unique validation error if an autotester returns an autotest_settings_id number to be set on remote_autotest_settings_id, but that number has already been taken by another autotester. We would want to allow this kind of scenario.

To fix this, we will need to update the unique validation constraint to have the remote_autotest_settings_id to be unique to an autotester.

Testing steps:

  1. set the remote_autotest_settings_id to Null in the assignment_properties table for the assignment you are working with.
  2. on the redis side of the autotester, set the key "autotest:settings_id" to an existing number in the remote_autotest_settings_id column on its next increment, and ensure they are within the same course.
  3. On the UI side, try to save the autotest settings for the assignment in question. You will see an error message appearing: 'Assignment properties remote autotest settings remote_autotest_settings_id has already been taken by the same autotester.'

...

Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue) x
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@donny-wong donny-wong force-pushed the update_remote_autotest_settings_id_validation branch from 1b040f4 to 4a7218b Compare January 27, 2025 20:09
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 12998164448

Details

  • 23 of 23 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 91.869%

Totals Coverage Status
Change from base Build 12997220848: 0.004%
Covered Lines: 41280
Relevant Lines: 44252

💛 - Coveralls


# Ensure remote_autotest_settings_id is unique for a given autotester
def remote_autotest_settings_id_check
unless self.remote_autotest_settings_id.nil?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of having the check here, use the :if argument to validate at the top

@@ -126,4 +126,18 @@ def not_timed_and_scanned
msg = I18n.t('activerecord.errors.models.assignment_properties.attributes.is_timed.not_scanned')
errors.add(:base, msg) if is_timed && scanned_exam
end

# Ensure remote_autotest_settings_id is unique for a given autotester
def remote_autotest_settings_id_check
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name "check" is a bit generic. Please rename to remote_autotest_settings_id_uniqueness

# Ensure remote_autotest_settings_id is unique for a given autotester
def remote_autotest_settings_id_check
unless self.remote_autotest_settings_id.nil?
assign_prop = AssignmentProperties.joins(assignment: :course).where(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This query is good but can be improved in two ways:

  1. Add a .not query to eliminate the record with id: self.id. Note that this can be chained with the original query, i.e., you can have a .where(...).not.where(...)
  2. Add a .exists? at the end, this will simplify the return value to just a boolean that you can use for the condition.

)
if assign_prop.count == 1 && self.id != assign_prop.first.id
errors.add(:remote_autotest_settings_id,
'remote_autotest_settings_id has already been taken by the same autotester.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make this an internationalized string. You can add it to the corresponding models YML file.

it { is_expected.to validate_uniqueness_of(:remote_autotest_settings_id).allow_nil }
it 'should not be valid when already taken by the same autotester' do
expect(assignment2).not_to be_valid
expect(assignment2.errors.full_messages[0]).to include('remote_autotest_settings_id has already been taken')
Copy link
Collaborator

Choose a reason for hiding this comment

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

refer to the internationalized string (which I asked you to add in an above comment)

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.

3 participants