Repository navigation
Move ajax_upload_image's image checks into a helper (Sonar S3776) - #564
Merged
Merged
Conversation
Sonar python:S3776: ajax_upload_image was still at cognitive complexity 17 after #539. The ImageCheck setup and the type, size and dimension checks move verbatim into _uploaded_image_errors(), called after the temporary file is written, as before. The cleanup, the 'There was an error uploading your preview.' branch and the response stay in the view. @json_view stays on ajax_upload_image. Refs #419
2 tasks
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Last round 3 item for thunderbird/addons-server#419. The stage-eks analysis at 02:28Z (a5b5fc6) still shows python:S3776
AaEh91ckMSBE_HpBvXpPatsrc/olympia/devhub/views.py:998:ajax_upload_imageat cognitive complexity 17 after the #539 split.Change, no behavior change
_uploaded_image_errors(upload_preview, upload_type, is_preview)takes the block that buildsImageCheck, callsis_animated()(which cachesis_image()), and runs the type, size, persona, preview and icon checks, with the waffle switch read at the same point. The block moves verbatim and returns the error list, which the viewextends intoerrors.is_preview(upload_type == 'preview', a pure comparison) is computed in the view, since the unlink check still needs it, and passed in.is_iconandis_personamove into the helper.elsebranch ("There was an error uploading your preview."), theupload_hashreset on errors and the returned dict are untouched.amo_utils,waffle,storage, ...) are still looked up at call time.Decorators checked:
ajax_upload_imagestill carries@json_view, directly above itsdef, andupload_imagekeeps@dev_required._uploaded_image_errorsis undecorated. The AST decorator comparison against stage-eks shows 0 changes.Sonar issues closed
AaEh91ckMSBE_HpBvXpPpython:S3776src/olympia/devhub/views.py:998Tests
flake8 is clean on changed lines. CI pytest covers
devhub/tests/test_views_edit.py(the upload_image tests). I'll check this PR's Sonar analysis shows no S3776 left indevhub/views.py. Local Greptile review skipped: org quota.