Skip to content

fix(views): emit deprecated-endpoint log warning once per endpoint per process#41286

Open
eschutho wants to merge 2 commits into
apache:masterfrom
eschutho:fix/deprecated-decorator-warn-once
Open

fix(views): emit deprecated-endpoint log warning once per endpoint per process#41286
eschutho wants to merge 2 commits into
apache:masterfrom
eschutho:fix/deprecated-decorator-warn-once

Conversation

@eschutho

Copy link
Copy Markdown
Member

Summary

Deprecation warning found in production Datadog:
Superset.explore_json This API endpoint is deprecated and will be removed in version 5.0.0

This message fired on every HTTP request to any endpoint decorated with @deprecated in views/base.py. The explore_json endpoint — still used by legacy chart types with useLegacyApi: true — was generating this warning thousands of times per day, making the log signal meaningless and adding noise to Datadog.

What changed:

  • Added a _warned = False closure variable inside _deprecated (one flag per decorated endpoint, allocated at decoration time).
  • The warning now fires exactly once per endpoint per worker process on the first call to that endpoint.
  • Subsequent requests to the same deprecated endpoint are handled silently.
  • Message text and format are unchanged.

No behavior change: the endpoint continues to respond normally on every request. Only the repeated log line is suppressed.

Thread safety: the first-call race on multi-threaded workers is benign — at worst two or three log lines on startup, then silence. No lock needed.

Test plan

  • Verify explore_json deprecation warning appears exactly once in logs after a gunicorn worker starts (not on every request)
  • Verify the endpoint itself still returns correct responses (no logic change)
  • Run existing integration tests: pytest tests/integration_tests/core_tests.py -k explore_json
  • Confirm no existing tests assert the warning fires on every request (none exist: grep -rn "deprecated.*Warning" tests/ returns no hits for views/base)

🤖 Generated with Claude Code

The `deprecated` decorator in views/base.py logged a WARNING on every
HTTP request to any deprecated endpoint.  In production, `explore_json`
is called by legacy chart types on every chart render, flooding logs with
the same message thousands of times per day and making the signal
meaningless.

Add a per-endpoint `_warned` flag (closure variable inside `_deprecated`)
so the warning fires exactly once per endpoint per worker process.
Subsequent requests to the same deprecated endpoint are handled silently.

The warning message and format are unchanged; only the repetition is
eliminated.  A benign first-call race on multi-threaded workers may emit
two or three log lines per worker on startup, which is acceptable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dosubot dosubot Bot added the logging Creates a UI or API endpoint that could benefit from logging. label Jun 22, 2026
@bito-code-review

bito-code-review Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #d1ac83

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: b2e6877..b2e6877
    • superset/views/base.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@eschutho eschutho requested a review from betodealmeida June 22, 2026 16:23
…vior

Self-review (019ef022-d140-77b3-bd7a-6e32a74ea00b) required a test to
guard the _warned closure flag introduced in the prior commit.

Verifies that calling a @deprecated-decorated endpoint twice emits
exactly one logger.warning call.

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

netlify Bot commented Jun 22, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

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

Comment thread superset/views/base.py
Comment on lines +177 to +192
nonlocal _warned
if not _warned:
_warned = True
message = (
"%s.%s "
"This API endpoint is deprecated and will be removed in version %s"
)
logger_args = [
self.__class__.__name__,
f.__name__,
eol_version,
]
if new_target:
message += " . Use the following API endpoint instead: %s"
logger_args.append(new_target)
logger.warning(message, *logger_args)

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: The new one-time warning guard is not thread-safe: concurrent first requests can both pass the if not _warned check before either write is visible to the other, so the warning can still be emitted multiple times in a worker. This violates the intended "once per endpoint per process" behavior; guard the check/update with a lock (or another atomic one-time primitive) around the warning block. [race condition]

Severity Level: Minor 🧹
- ⚠️ Deprecated explore_json logs may duplicate under concurrent load.
- ⚠️ Deprecation logging not strictly once-per-process as intended.
Steps of Reproduction ✅
1. Observe the deprecated decorator implementation in `superset/views/base.py` at lines
15–48 (Read output), specifically the inner `wraps` function where the guard is
implemented (diff hunk lines 176–193): it uses `nonlocal _warned`, checks `if not
_warned:`, then sets `_warned = True` and emits `logger.warning(...)` without any
synchronization.

2. Confirm that a real HTTP endpoint uses this decorator: in `superset/views/core.py`
lines 280–319, the `explore_json` view is exposed via `@expose("/explore_json/",
methods=("GET","POST"))` and
`@expose("/explore_json/<datasource_type>/<int:datasource_id>/", ...)`, and is decorated
with `@deprecated(eol_version="5.0.0", new_target="/api/v1/chart/data")` at line 18 (Read
output), so every call to `/explore_json` passes through the `_warned` guard in
`superset/views/base.py`.

3. Run Superset with this PR code under a multi-threaded WSGI server (e.g., gunicorn
worker configured with `--threads > 1`), so that multiple requests to `/explore_json` can
be processed concurrently by the same process and thus share the same `_warned` closure
defined in `deprecated` at `superset/views/base.py:24–46`.

4. Immediately after starting a worker, send two or more concurrent HTTP requests to
`/explore_json` (or `/explore_json/<datasource_type>/<datasource_id>/`) so they reach the
same process at nearly the same time; due to the unsynchronized `if not _warned: _warned =
True` sequence in `superset/views/base.py` lines 28–31, two threads can both see `_warned`
as `False` before either write is visible, causing the warning block to execute in both
threads and resulting in multiple `"This API endpoint is deprecated and will be removed in
version %s"` log entries instead of a single once-per-process warning.

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:** superset/views/base.py
**Line:** 177:192
**Comment:**
	*Race Condition: The new one-time warning guard is not thread-safe: concurrent first requests can both pass the `if not _warned` check before either write is visible to the other, so the warning can still be emitted multiple times in a worker. This violates the intended "once per endpoint per process" behavior; guard the check/update with a lock (or another atomic one-time primitive) around the warning block.

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
👍 | 👎

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.76%. Comparing base (defacc3) to head (5e06591).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #41286      +/-   ##
==========================================
- Coverage   64.36%   63.76%   -0.60%     
==========================================
  Files        2653     2653              
  Lines      144867   144965      +98     
  Branches    33421    33452      +31     
==========================================
- Hits        93250    92444     -806     
- Misses      49946    50836     +890     
- Partials     1671     1685      +14     
Flag Coverage Δ
hive 39.29% <11.11%> (-0.05%) ⬇️
mysql 58.02% <100.00%> (-0.04%) ⬇️
postgres 58.08% <100.00%> (-0.05%) ⬇️
presto 40.87% <11.11%> (-0.06%) ⬇️
python 58.30% <100.00%> (-1.28%) ⬇️
sqlite 57.74% <100.00%> (-0.04%) ⬇️
unit ?

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.

@bito-code-review

bito-code-review Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #6979ad

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: b2e6877..5e06591
    • tests/unit_tests/views/test_base.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 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

logging Creates a UI or API endpoint that could benefit from logging. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant