Skip to content

Finish round 3 singletons: S8519, S112, ratings S3776 (Sonar) - #562

Merged
mzeier merged 1 commit into
stage-eksfrom
419/r3-s8519-s112-ratings
Oct 10, 2026
Merged

mzeier merged 1 commit into
stage-eksfrom
419/r3-s8519-s112-ratings

Conversation

@mzeier

@mzeier mzeier commented Oct 10, 2026

Copy link
Copy Markdown

Round 3 remainder for thunderbird/addons-server#419, as listed in the coordinator's status note: S8519, the two S112s, and the ratings S3776 still over 15 after #535.

Changes, each with its no-behavior-change argument

  1. python:S8519 src/olympia/amo/search.py ES.__getitem__ (AaEh92RwMSBE_HpBvXx8 (line 104)). return list(new)[0] becomes return _first_item(new). This is the _first_item() pattern from P1-11: Sonar fixes in activity (S8512, S8519, S7496, S5806, S1192, S2638, S1172, S1940) #473: next(iter(...)), re-raising IndexError('list index out of range') on an empty result, the same type and message list(...)[0] raised.
    • Query count is unchanged. list(new) called ES.__len__ and then ES.__iter__. Both go through _do_search(), which caches _results_cache, so that was one ES query. next(iter(new)) calls __iter__ -> _do_search() once: still one ES query.
    • For object results, the original len() evaluated the type.objects.filter(id__in=...) queryset, and ObjectSearchResults.__iter__ then reused its cache. Now __iter__ evaluates it, still exactly once. That generator builds its dict eagerly, so taking only the first element skips no work.
  2. python:S112 src/olympia/amo/utils.py resize_image (AaEh92NnMSBE_HpBvXxT (line 668)): Exception becomes ValueError, with the same message. Callers:
    • devhub/tasks.py (icon/preview resizing) and users/tasks.py wrap it in except Exception, which still catches ValueError.
    • versions/tasks.py and the other devhub calls don't catch it, so it propagates as before.
    • amo/tests/test_amo_utils.py::test_resize_image uses pytest.raises(Exception, match=...), which still passes.
  3. python:S112 src/olympia/lib/settings_base.py read_only_mode (AaEh92ixMSBE_HpBvX1X (line 1451)): Exception becomes RuntimeError, with the same message. No caller catches it: it runs at settings import (or amo/tests/test_readonly.py's fixture with a valid env). I used a built-in so the settings module doesn't gain a Django import.
  4. python:S3776 src/olympia/ratings/views.py RatingViewSet.filter_queryset (AaEh92f7MSBE_HpBvX0l (line 373)): the whole if self.action == 'list': body moves verbatim into _filter_list_queryset(qs), which returns qs. The same parameters are read and parsed in the same order, with the same ParseError messages and the same self.pagination_class assignment. filter_queryset still calls super().filter_queryset(qs) last.

Decorators checked: the AST comparison of every pre-existing function's decorator list between stage-eks and this branch shows 0 changes. RatingViewSet.filter_queryset and ES.__getitem__ carry no decorators, before or after; _first_item and _filter_list_queryset are new and undecorated.

Tests

flake8 is clean on changed lines. CI pytest covers amo/tests/test_search.py, amo/tests/test_amo_utils.py, amo/tests/test_readonly.py and ratings/tests/test_views.py. Local Greptile review skipped: org quota.

- amo.search.ES.__getitem__ (python:S8519): _first_item() takes the first
  result without list(); it still raises IndexError on an empty result.
  Same queries: _do_search caches, so one ES query, and for object
  results the queryset is evaluated once either way.
- amo.utils.resize_image and lib.settings_base.read_only_mode
  (python:S112): ValueError and RuntimeError instead of bare Exception,
  same messages. Every caller that catches it uses except Exception, so
  it is still caught.
- ratings.views.RatingViewSet.filter_queryset (python:S3776, still 18
  after #535): the list-action body moves verbatim into
  _filter_list_queryset().

Refs #419
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Python Test Results

5 763 tests  +5 763   5 709 ✅ +5 709   6m 42s ⏱️ + 6m 42s
    1 suites +    1      54 💤 +   54 
    1 files   +    1       0 ❌ ±    0 

Results for commit c0a63ac. ± Comparison against base commit 1039ee9.

@mzeier
mzeier merged commit a5b5fc6 into stage-eks Oct 10, 2026
3 checks passed
@mzeier
mzeier deleted the 419/r3-s8519-s112-ratings branch October 10, 2026 02:27
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.

1 participant