Skip to content

fix: close gaps in pkg_resources/sqlalchemy-redshift warning suppression#41935

Open
eschutho wants to merge 3 commits into
apache:masterfrom
eschutho:fix/pkg-resources-redshift-warning-suppression
Open

fix: close gaps in pkg_resources/sqlalchemy-redshift warning suppression#41935
eschutho wants to merge 3 commits into
apache:masterfrom
eschutho:fix/pkg-resources-redshift-warning-suppression

Conversation

@eschutho

Copy link
Copy Markdown
Member

What warning

Datadog showed the third-party UserWarning: pkg_resources is deprecated as an API (raised from sqlalchemy-redshift's own __init__.py, which still does from pkg_resources import ...) firing at high volume (~76/day) in production logs, split across the main web/celery process (py3.10) and superset/mcp_service (a separate py3.11 process).

There's already an attempted suppression for this in superset/db_engine_specs/redshift.py (warnings.filterwarnings("ignore", message=r"pkg_resources is deprecated as an API")), with a comment reasoning that Database.db_engine_spec is always accessed (which imports this module) before create_engine() ever triggers SQLAlchemy's lazy dialect import of sqlalchemy_redshift. Despite that, the warning is still firing in production, so the existing fix has a gap somewhere in the ordering.

What changed

  • superset/mcp_service/__init__.py + superset/mcp_service/server.py: added the same filter, mirroring the exact existing pattern already used for the authlib.jose deprecation warning in these same two files (mcp_service is a separate process/import graph from the main app and had zero suppression for this specific warning).
  • superset/utils/logging_configurator.py: registered the same filter unconditionally in DefaultLoggingConfigurator.configure_logging(), which runs first thing in SupersetAppInitializer.init_app() (both the web app and celery workers go through create_app()init_app()). This is a more robust, order-independent suppression point that doesn't depend on Database.db_engine_spec having been accessed first.
  • superset/db_engine_specs/redshift.py: left the original filter in place (harmless, idempotent) and updated its comment to point at the new primary suppression location.

No behavior change

Purely additive warnings.filterwarnings("ignore", ...) calls — no change to any request/response behavior, just suppressing log noise from a warning that carries no actionable signal (the underlying sqlalchemy-redshift pin can't move past <0.9 to the pkg_resources-free 1.0.0 release without a SQLAlchemy 2.0 migration, per the existing comment referencing #39750).

Test plan

  • python3 -m py_compile on all 4 changed files — clean.
  • ruff check — clean.
  • Verified live in a Python shell that registering the exact filter added here suppresses the literal warning text as raised by the installed pkg_resources/setuptools 80.x package.
  • Confirmed via code trace that celery's worker entrypoint (superset/tasks/celery_app.py) calls create_app(), so it goes through the same init_app()configure_logging() path as the web process.
  • Grepped the repo for other sqlalchemy_redshift/create_engine( touchpoints — no additional code paths need their own filter.
  • Existing unit tests unaffected (no assertions cover this specific filter today, consistent with existing coverage of the authlib.jose filter it mirrors).

The pkg_resources UserWarning from sqlalchemy-redshift's __init__.py
(apache#36082) was already suppressed in db_engine_specs/redshift.py, but
production logs still show ~76/day of it firing:

- mcp_service runs as a separate process and never imports
  db_engine_specs/redshift.py, so it had no filter for this warning at
  all (unlike its sibling authlib.jose filter, which is present in both
  __init__.py and server.py). Added it in both places, mirroring the
  existing authlib.jose pattern exactly.
- The main web/celery filter only registers the first time something
  accesses Database.db_engine_spec, which isn't guaranteed to be the
  first thing to run in every process. Registered the same filter
  unconditionally in DefaultLoggingConfigurator.configure_logging(),
  which runs first in SupersetAppInitializer.init_app(), as a more
  robust primary suppression point. The existing redshift.py filter is
  left in place as a fallback for standalone scripts.
@dosubot dosubot Bot added data:connect:redshift Related to Redshift infra:logging Infra setup - logging labels Jul 10, 2026
@bito-code-review

bito-code-review Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #d1c7d3

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/mcp_service/server.py - 1
    • Redundant warning filter · Line 87-93
      The `pkg_resources` warning filter at lines 87-93 is duplicative. The same filter is already registered in `superset/mcp_service/__init__.py` (line 55-58) when the package is first imported, which occurs before `_suppress_third_party_warnings()` is called in `run_mcp_server()` (line 877). Since `filterwarnings()` is globally applied and idempotent, this duplicate registration serves no purpose.
Review Details
  • Files reviewed - 4 · Commit Range: 16db953..16db953
    • superset/db_engine_specs/redshift.py
    • superset/mcp_service/__init__.py
    • superset/mcp_service/server.py
    • superset/utils/logging_configurator.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 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@eschutho
eschutho requested a review from richardfogaca July 10, 2026 16:30
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.47%. Comparing base (a6ce2fd) to head (3fd3db5).
⚠️ Report is 296 commits behind head on master.

Files with missing lines Patch % Lines
superset/initialization/__init__.py 50.00% 0 Missing and 2 partials ⚠️
superset/mcp_service/server.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41935      +/-   ##
==========================================
- Coverage   64.77%   64.47%   -0.31%     
==========================================
  Files        2739     2780      +41     
  Lines      152981   156731    +3750     
  Branches    35058    35561     +503     
==========================================
+ Hits        99101   101057    +1956     
- Misses      51980    53706    +1726     
- Partials     1900     1968      +68     
Flag Coverage Δ
hive 38.74% <50.00%> (-0.34%) ⬇️
mysql 57.65% <50.00%> (-0.36%) ⬇️
postgres 57.71% <50.00%> (-0.36%) ⬇️
presto 40.65% <50.00%> (-0.39%) ⬇️
python 59.09% <50.00%> (-0.36%) ⬇️
sqlite 57.32% <50.00%> (-0.35%) ⬇️
unit 100.00% <ø> (ø)

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.

@richardfogaca richardfogaca 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.

Richard's agent here:

Functional — worth resolving before merge

  • superset/utils/logging_configurator.py:65: could we move this filter to SupersetAppInitializer.configure_logging() before it delegates to LOGGING_CONFIGURATOR, or another common startup hook? LOGGING_CONFIGURATOR is replaceable, so deployments with a custom configurator skip DefaultLoggingConfigurator.configure_logging() and still depend on the original order-sensitive Redshift import filter. That leaves the web/Celery gap open for those deployments.

Other suggestion

  • Could we extend the existing test_suppress_third_party_warnings to assert the new pkg_resources filter, plus cover the final app/worker startup location? Right now that test still passes if the new MCP filter is removed.

The focused implementation and dependency rationale look good otherwise. Reviewed at 16db953; CI is green.

Comment on lines +150 to +157
pkg_resources_filters = [
f
for f in warnings.filters
if f[0] == "ignore"
and isinstance(f[1], re.Pattern)
and f[1].pattern == r"pkg_resources is deprecated as an API"
]
assert len(pkg_resources_filters) >= 1, "Expected pkg_resources warning filter"

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.

Suggestion: Add an explicit type annotation to the newly introduced warning-filter collection variable. [custom_rule]

Severity Level: Minor 🧹

Why it matters? ⭐

The added local variable pkg_resources_filters is a clearly typable Python variable introduced in a new hunk and it has no annotation. This matches the rule requiring type hints for relevant variables that can be annotated.

Rule source 📖

.cursor/rules/dev-standard.mdc (line 28)

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/mcp_service/test_mcp_server.py
**Line:** 150:157
**Comment:**
	*Custom Rule: Add an explicit type annotation to the newly introduced warning-filter collection variable.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The variable pkg_resources_filters is a list of filter tuples, which can be explicitly annotated as list[Any] or list[tuple[Any, ...]] to improve type safety and readability.

To resolve this, you can update the variable declaration in tests/unit_tests/mcp_service/test_mcp_server.py as follows:

    pkg_resources_filters: list[Any] = [
        f
        for f in warnings.filters
        if f[0] == "ignore"
        and isinstance(f[1], re.Pattern)
        and f[1].pattern == r"pkg_resources is deprecated as an API"
    ]

I have checked the other comments on this PR, and there are no other pending review comments to address. Would you like me to perform any other tasks?

tests/unit_tests/mcp_service/test_mcp_server.py

pkg_resources_filters: list[Any] = [
        f
        for f in warnings.filters
        if f[0] == "ignore"
        and isinstance(f[1], re.Pattern)
        and f[1].pattern == r"pkg_resources is deprecated as an API"
    ]

@bito-code-review

bito-code-review Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #0829e6

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/unit_tests/mcp_service/test_mcp_server.py - 1
Review Details
  • Files reviewed - 4 · Commit Range: 16db953..d36a680
    • superset/db_engine_specs/redshift.py
    • superset/initialization/__init__.py
    • superset/utils/logging_configurator.py
    • tests/unit_tests/mcp_service/test_mcp_server.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 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas

Copy link
Copy Markdown
Member

Thanks for tracking down the gap, this looks like the right fix and the reasoning on the three suppression points is solid. ruff-format is failing on test_mcp_server.py though, might want to run pre-commit locally and repush before this goes green.

Aligns with CI's pinned ruff version; no behavior change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@netlify

netlify Bot commented Jul 22, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 3fd3db5
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a60100e6e2b010008d3a148
😎 Deploy Preview https://deploy-preview-41935--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.

@eschutho
eschutho requested a review from richardfogaca July 22, 2026 01:09

@richardfogaca richardfogaca 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.

Richard's agent here:

Functional — worth resolving before merge

  • The new unconditional filters match only the warning message, so they suppress the same pkg_resources warning from every extension or dependency, not just sqlalchemy-redshift. Since setuptools emits it as a UserWarning with stacklevel=2, could we scope each filter with category=UserWarning and module=r"sqlalchemy_redshift(?:\\..*)?"? That preserves unrelated dependency-migration signals.

Other suggestions

  • Could we add a regression test proving SupersetAppInitializer.configure_logging() installs the filter before a custom LOGGING_CONFIGURATOR runs? The current MCP test already sees the package-level filter during import, so it does not independently exercise _suppress_third_party_warnings().
  • The additional server.py registration appears redundant because superset.mcp_service.__init__ necessarily runs first and the filter persists. Could we remove it unless there is a real reset scenario to cover?
  • Could we make the changed comments timeless and refresh the PR description? It still describes logging_configurator.py as the final owner and says no test assertion was added.

Reviewed at 3fd3db5; current CI is green.

@bito-code-review

bito-code-review Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #db17ce

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: d36a680..3fd3db5
    • tests/unit_tests/mcp_service/test_mcp_server.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 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:connect:redshift Related to Redshift infra:logging Infra setup - logging size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants