Skip to content

fix(db-engine): make cachetools import optional in aws_iam - #38269

Merged
rusackas merged 6 commits into
apache:masterfrom
preset-io:fix/cachetools
Oct 13, 2026
Merged

rusackas merged 6 commits into
apache:masterfrom
preset-io:fix/cachetools

Conversation

@dpgaspar

Copy link
Copy Markdown
Member

SUMMARY

google-auth 2.48.0 dropped cachetools from its dependencies, breaking the transitive dependency chain (shillelagh → google-auth → cachetools) that previously guaranteed its availability. While requirements/base.txt still pins cachetools==6.2.1, a fresh pip install apache-superset from pyproject.toml can resolve google-auth>=2.48.0 and fail with an ImportError when loading superset.db_engine_specs.aws_iam.

This PR wraps the cachetools import in a try/except with a plain dict fallback, consistent with how boto3 is already lazily imported in the same file. When cachetools is available, TTLCache is used as before; when it isn't, the cache degrades to a plain dict (no TTL expiry, but the feature still works).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — no UI changes.

TESTING INSTRUCTIONS

  1. Uninstall cachetools from your environment
  2. Verify Superset starts without ImportError from aws_iam.py
  3. Reinstall cachetools and verify the TTLCache-based credential caching still works

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

google-auth 2.48.0 dropped cachetools from its dependencies, breaking
the transitive chain that previously guaranteed its availability. Wrap
the import in try/except with a plain dict fallback so the module loads
even when cachetools is not installed.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@bito-code-review

bito-code-review Bot commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8bf641

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: ea800f4..ea800f4
    • superset/db_engine_specs/aws_iam.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/db_engine_specs/aws_iam.py Resolved
@dosubot dosubot Bot added the change:backend Requires changing the backend label Feb 26, 2026
@netlify

netlify Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit baa4099
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6abef530608a5a0009a10a00
😎 Deploy Preview https://deploy-preview-38269--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.05%. Comparing base (f8caa2b) to head (baa4099).
⚠️ Report is 605 commits behind head on master.

Files with missing lines Patch % Lines
superset/db_engine_specs/aws_iam.py 83.33% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #38269      +/-   ##
==========================================
- Coverage   80.13%   79.05%   -1.08%     
==========================================
  Files        2922     2875      -47     
  Lines      172088   173796    +1708     
  Branches    39941    38629    -1312     
==========================================
- Hits       137904   137403     -501     
- Misses      31607    33657    +2050     
- Partials     2577     2736     +159     
Flag Coverage Δ
hive 36.54% <61.11%> (-0.85%) ⬇️
mysql 55.54% <61.11%> (-1.44%) ⬇️
postgres 55.55% <61.11%> (-1.46%) ⬇️
presto 38.45% <61.11%> (-0.84%) ⬇️
python 85.95% <83.33%> (+1.43%) ⬆️
sqlite 55.27% <61.11%> (-1.43%) ⬇️
unit 78.92% <83.33%> (+3.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread superset/db_engine_specs/aws_iam.py Resolved

@Vitor-Avila Vitor-Avila left a comment

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.

Left a non-blocking comment. I'm fine with the way it is, just thinking that we could also just raise and force the user to install the missing dep.

@Vitor-Avila

Copy link
Copy Markdown
Contributor

thanks for working on this btw! I faced an error for missing this dependency last week and wasn't sure why -- now I know! 🙌

@rusackas rusackas added the review:checkpoint Last PR reviewed during the daily review standup label Mar 9, 2026
@sadpandajoe sadpandajoe removed the review:checkpoint Last PR reviewed during the daily review standup label Mar 16, 2026
Comment thread superset/db_engine_specs/aws_iam.py Resolved
Comment thread superset/db_engine_specs/aws_iam.py Resolved
@rusackas

rusackas commented Sep 9, 2026

Copy link
Copy Markdown
Member

@dpgaspar checking in... want help with getting this across the finish line? I'll update the branch now for good measure.

rusackas and others added 2 commits September 9, 2026 11:53
A plain dict never evicts, so once an STS credential's real 600s TTL
elapsed, every call after that would keep reusing the same expired
credentials until the process restarted -- the opposite of "the feature
still works" this fallback was meant to provide. Replace it with a
MutableMapping that always misses, so get_iam_credentials falls through
to a fresh assume_role call every time cachetools isn't installed.

Also satisfies the open review threads: a no-op cache closes the
TTL-less staleness bug CodeAnt flagged twice without reintroducing the
ImportError this PR exists to avoid (the alternative raised on the
Vitor-Avila thread), and gives the fallback assignment its own type
annotation per CodeAnt's minor note.

Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
@pull-request-size pull-request-size Bot added size/L and removed size/S labels Oct 2, 2026
@rusackas

rusackas commented Oct 2, 2026

Copy link
Copy Markdown
Member

Pushed baa4099 to fix the failing pre-commit (ruff-format) and address the open review threads:

  • Replaced the plain-dict cachetools fallback with a no-op MutableMapping (_NoCache) that always misses, so get_iam_credentials re-assumes the IAM role fresh every time instead of reusing the same STS credentials forever past their real 600s TTL — closes the staleness bug CodeAnt flagged (twice) without reintroducing the ImportError this PR exists to avoid, which a hard raise (per @Vitor-Avila's suggestion) would have done.
  • Gave the fallback assignment its own type annotation per CodeAnt's minor note.
  • Added two regression tests covering the no-op cache directly and the end-to-end "never caches without cachetools" behavior.

CI should be green shortly; will keep an eye on it.

@rusackas

rusackas commented Oct 2, 2026

Copy link
Copy Markdown
Member

@Vitor-Avila @dpgaspar check my work, and merge if you dig it :D

@bito-code-review bito-code-review Bot left a comment •

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.

Code Review Agent Run #979562

Actionable Suggestions - 1
  • superset/db_engine_specs/aws_iam.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: ea800f4..baa4099
    • superset/db_engine_specs/aws_iam.py
    • tests/unit_tests/db_engine_specs/test_aws_iam.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +86 to +91
try:
from cachetools import TTLCache

_credentials_cache = TTLCache(maxsize=100, ttl=600)
except ImportError:
_credentials_cache = _NoCache()

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.

Dead fallback code

cachetools is a hard dependency (pyproject.toml:45, requirements/base.txt:47, requirements/development.txt:115), so the except ImportError branch and the whole _NoCache class are unreachable in any supported install. This is ~40 lines of dead code that also misleads readers into thinking cachetools is optional. Either drop the fallback or document the environment that can lack cachetools.

Code Review Run #979562


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@rusackas

Copy link
Copy Markdown
Member

@Vitor-Avila checking back in. Your approval predates my push in baa4099, which swapped the plain-dict fallback for a no-op cache instead of raising (so there's no stale-credential risk and no ImportError). CI is green and the branch is clean against master. Mind taking a quick look at the new approach? If it works for you, I think this is good to merge.

@rusackas
rusackas merged commit 488810d into apache:master Oct 13, 2026
99 checks passed
@rusackas
rusackas deleted the fix/cachetools branch October 13, 2026 16:17
villebro pushed a commit that referenced this pull request Oct 16, 2026
Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: Evan Rusackas <[email protected]>
Co-authored-by: Evan Rusackas <[email protected]>
(cherry picked from commit 488810d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants