Open amelsmajic opened 3 years ago
validates :submitter, presence: true
validates :submitted_at, presence: true
validates :exercise, presence: true
validates :student_group, uniqueness: { scope: [:exercise_id, :exercise_attempt_id] }, if: :student_group
validate :upload_size_below_exercise_maximum_upload_size
I guess out of all the things we validate here only the last validation is related to this issue anyways, and as you said this should not trigger when deleting assets.
Could you open up a PR with these changes?
In app/services/submission_extraction_service.rb:25
# needs to be reset, in order to allow correct file-size validation
submission_asset.processed_size = 0
submission_asset.save(validate: false)
Looks to me as if setting the processed_size
is no longer sufficient. IMHO this is the place where we need to modify the code.
On production we currently have the following error popping up:
This happens during extraction:
when the archive is being removed:
because the following function is called:
which performs a validation during save:
The problem is that even though the extracted files are below the maximum upload size, during the validation of the submission both the extracted files and the zip are summed together and checked if below the maximum upload size which leads to the validation failing.
The exact line triggering the validation is here: https://github.com/matthee/Sapphire/blob/bfa299fbf2c39104a124d38aa685a113af7cf21e/app/models/submission_asset.rb#L198
My suggestion for a fix would be not validating if the submission_asset is a archive:
Or even not validating at all here:
As we cannot be above the maximum upload size after removing a file. Open for other suggestions.