Skip to content

[FSSDK-13482] Fix Arnica findings: setup.py exec and http session mount - #529

Merged
Esra Kartal (esrakartalOpt) merged 5 commits into
masterfrom
fssdk-13482-fix-arnica-findings
Nov 23, 2026
Merged

Esra Kartal (esrakartalOpt) merged 5 commits into
masterfrom
fssdk-13482-fix-arnica-findings

Conversation

@esrakartalOpt

@esrakartalOpt Esra Kartal (esrakartalOpt) commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • setup.py: read the package version by parsing the version_info tuple literal from optimizely/version.py (regex plus ast.literal_eval) instead of calling exec() on the file (Arnica "Exec detected" finding). It raises a clear error if version_info is not found. python setup.py --version still prints 5.8.0.
  • Add optimizely/helpers/retry_session.py with create_retry_session(...), and use it in event_dispatcher.py and config_manager.py (two places). This replaces three copies of the same retry session setup, including the session.mount('http://', adapter) call that Arnica flags as "Request session with HTTP", with one documented call. Behavior is unchanged: the same retry adapter is still registered for both https:// and http://, retries stays Optional[int] as before, and status_forcelist defaults to (500, 502, 503, 504), which all three callers used.
  • The http:// mount is kept on purpose, so retries still apply to user-configured http:// datafile URLs and event endpoints (the SDK defaults are all https://). Registering an adapter does not send anything over http://. The call carries a bare nosemgrep comment, because the full rule id does not fit in the repo's 120 character line limit. If Arnica does not honor it, dismiss the finding there with the reason above.
  • Remove the now-unused requests import from event_dispatcher.py.

Notes

  • test (3.9) fails in CI because ubuntu-latest is now Ubuntu 26.04, which has no Python 3.9 build for setup-python. This is a pre-existing failure on master, not caused by this PR. Dropping Python 3.9 from the matrix is tracked separately in FSSDK-13301, so this PR does not change the CI matrix.
  • optimizely/fullstack-prod-suite (python) also fails on master, at the "Configure AWS Credentials" step of that other repo's pipeline.

Test plan

  • python -m pytest tests: 1048 passed
  • ruff check . and mypy . --exclude "tests/testapp" and mypy . --exclude "tests/" --strict: all pass
  • Added tests/helpers_tests/test_retry_session.py: the helper returns a session with the retry adapter (retries, backoff factor and status codes) on both https:// and http://, and status_forcelist has the expected default
  • python setup.py --version prints 5.8.0, same as optimizely.version.__version__

Issues

  • FSSDK-13482

🤖 Generated with Claude Code

- setup.py: read the version by parsing the version_info literal from
  optimizely/version.py instead of exec()-ing the file.
- Add create_retry_session helper and use it in event_dispatcher and
  config_manager, replacing three duplicated session.mount('http://', ...)
  blocks with one documented, suppressed call. Behavior is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
config_manager passes self.retries, which is Optional[int]. Accept Optional[int]
(None means no total limit, same as urllib3's Retry) so type-check passes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Python 3.9 reached end of life in October 2025 and setup-python no longer finds
a 3.9 build on ubuntu-latest (now Ubuntu 26.04), so the test (3.9) job failed
before running any tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few small changes requested inline: default status_forcelist, and remove the duplicated http:// explanation. Also, please update the PR description: it still says Python 3.9 is dropped from CI, but that was reverted and is now tracked in FSSDK-13301. The rest looks good: the setup.py change and the caller swaps behave the same as before.

Comment thread optimizely/helpers/retry_session.py Resolved
Comment thread optimizely/helpers/retry_session.py Resolved
Comment thread optimizely/helpers/retry_session.py Resolved
…ed http:// note

- Default status_forcelist to (500, 502, 503, 504) in create_retry_session and
  drop the argument from the three callers.
- Keep the http:// explanation next to the mount call and shorten the docstring.
- Add a test for the default status_forcelist.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All comments addressed, thanks! LGTM 👍

The test (3.9) failure was already on master and will be fixed in FSSDK-13301.

@esrakartalOpt
Esra Kartal (esrakartalOpt) merged commit c792eac into master Nov 23, 2026
15 of 17 checks passed
@esrakartalOpt
Esra Kartal (esrakartalOpt) deleted the fssdk-13482-fix-arnica-findings branch November 23, 2026 17:12
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.

2 participants