Skip to content

fix(reports): respect Playwright wait event during auth - #43253

Closed
kakoni wants to merge 5 commits into
apache:masterfrom
kakoni:patch-4
Closed

kakoni wants to merge 5 commits into
apache:masterfrom
kakoni:patch-4

Conversation

@kakoni

@kakoni kakoni commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

MachineAuthProvider.authenticate_browser_context() calls page.goto(headless_url("/login/"))
without wait_until, so Playwright falls back to its load default. In deployments where
/login/ reaches domcontentloaded but never fires load, machine auth times out and the
report never gets to the screenshot step, even though the rest of the Playwright flow already
honors SCREENSHOT_PLAYWRIGHT_WAIT_EVENT.

This passes that config through to the auth navigation, making it consistent with the rest of
the screenshot flow. The default (domcontentloaded) resolves the timeout while staying
configurable.

TESTING INSTRUCTIONS

Against a deployment where /login/ never completes load:

  • page.goto(url, wait_until="load", timeout=60000) times out
  • page.goto(url, wait_until="domcontentloaded", timeout=60000) succeeds

Before the change, triggering a report snapshot fails during machine auth with
Page.goto: Timeout 60000ms exceeded ... waiting until "load". After, navigation completes and
the report proceeds. Also verified that setting the config to another supported Playwright event
is respected by the auth navigation.

@bito-code-review

bito-code-review Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #5221ff

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 0d3da10..0d3da10
    • superset/utils/machine_auth.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@kakoni kakoni changed the title Refactor page.goto to include wait_until parameter fix(reports): respect Playwright wait event during auth Aug 17, 2026
Comment thread superset/utils/machine_auth.py Resolved
@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The page.goto call lacks a timeout handler, which causes the authentication process to abort if the configured event (e.g., networkidle) takes longer than the default Playwright timeout. To resolve this, wrap the navigation in a try-except block to catch playwright.sync_api.TimeoutError and proceed with cookie installation regardless of the navigation timeout.

superset/utils/machine_auth.py

try:
            page.goto(
                headless_url("/login/"),
                wait_until=app.config["SCREENSHOT_PLAYWRIGHT_WAIT_EVENT"],
            )
        except Exception:
            pass

@codecov

codecov Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.26%. Comparing base (ac3c158) to head (1e4a1bc).
⚠️ Report is 417 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #43253   +/-   ##
=======================================
  Coverage   79.26%   79.26%           
=======================================
  Files        2888     2888           
  Lines      166464   166472    +8     
  Branches    38532    38532           
=======================================
+ Hits       131950   131958    +8     
  Misses      32026    32026           
  Partials     2488     2488           
Flag Coverage Δ
hive 37.89% <44.44%> (+<0.01%) ⬆️
mysql 57.57% <100.00%> (+<0.01%) ⬆️
postgres 57.61% <100.00%> (+<0.01%) ⬆️
presto 39.80% <44.44%> (+<0.01%) ⬆️
python 83.78% <100.00%> (+<0.01%) ⬆️
sqlite 57.30% <100.00%> (+<0.01%) ⬆️
unit 74.20% <44.44%> (-0.01%) ⬇️

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

Copy link
Copy Markdown
Contributor

AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).

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

@bito-code-review

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b608c4

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 5bcb565..5bcb565
    • superset/utils/machine_auth.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@sadpandajoe

Copy link
Copy Markdown
Member

@fitzee I think you were looking into alerts/reports so pinging you here.

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

Verdict: sound, well-targeted fix. It wraps the login goto in a timeout guard so a slow-loading login page can no longer abort report authentication, and it does so by mirroring the exact pattern already used for the screenshot navigation. I reviewed the pinned head 5bcb565; CI is green (60 success / 9 skipped / 3 neutral, no failures). Not blocking on anything below — a couple of small notes and one test suggestion.

The fall-through on timeout is safe (not a finding — worth stating explicitly). The concern with swallow-and-continue would be delivering an unauthenticated / login-page screenshot. That can't happen here:

  • Cookies are installed via browser_context.add_cookies(...) with an explicit domain=url.netloc (machine_auth.py:88-100). That does not depend on the goto having committed a navigation, so even a worst-case timeout leaving about:blank still installs the auth cookies on the context.
  • This /login/ page is never the screenshot target. The report image is captured downstream by a separate page.goto(url, ...) to the real chart/dashboard URL in webdriver.py:560, after self.auth() has populated the context (webdriver.py:544-545).

So the change is strictly more robust than before: previously the bare page.goto("/login/") used Playwright's default wait_until="load" and would raise and abort auth on a slow page. Nice fix.

Addresses the codeant finding. The prior review flagged that introducing wait_until (e.g. networkidle) without catching PlaywrightTimeout would break auth on timeout. The try/except PlaywrightTimeout + fall-through here is exactly that fix. Confirmed for the next reader.

Notes (all non-blocking):

  1. PlaywrightTimeout = Exception fallback — this matches webdriver.py:69-75 byte-for-byte, so it's consistent with the established convention. It's also effectively unreachable at runtime: this handler only runs when a real Playwright BrowserContext was passed in, which can't happen if playwright failed to import. Fine as-is; the narrower concern doesn't apply given the sibling precedent.
  2. Config key — SCREENSHOT_PLAYWRIGHT_WAIT_EVENT ships with a default (config.py:1324 = "domcontentloaded"), so no KeyError risk. Optional: read it into a local once instead of subscripting app.config[...] twice (the goto and the log line). Cosmetic.
  3. Minor behavior change — the login goto previously waited for "load" and now waits for the configured event (default domcontentloaded, which fires earlier). Benign, since login-page render doesn't affect cookie installation, and it aligns the two goto calls. Worth a mention in the description.
  4. logger.exception logs at ERROR with a traceback for a condition the code intentionally continues past; warning arguably fits better. That said, webdriver.py:570 does the identical logger.exception for the same case, so keeping it consistent is defensible.

Tests. A module already exists (tests/integration_tests/utils/machine_auth_tests.py) and already mocks mock_page.goto. The new fall-through branch is trivially testable — mock_page.goto.side_effect = PlaywrightTimeout(...) and assert add_cookies is still called once — in ~5 lines. The PR adds none; existing tests still pass because the branch isn't exercised. Not blocking for a change this small, but a single test guarding "timeout still installs cookies" would lock in the exact property that makes this safe.

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Aug 20, 2026
@netlify

netlify Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

@kakoni

kakoni commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@aminghadersohi Added the a single test guarding "timeout still installs cookies"

@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 #7e2347

Actionable Suggestions - 1
  • tests/integration_tests/utils/machine_auth_tests.py - 1
Review Details
  • Files reviewed - 1 · Commit Range: 5bcb565..48dab98
    • tests/integration_tests/utils/machine_auth_tests.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@bito-code-review

bito-code-review Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b0134b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 48dab98..bb15e94
    • tests/integration_tests/utils/machine_auth_tests.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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@kakoni

kakoni commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@aminghadersohi ping! Could you review this?

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

Round 2 — narrow scope. Since round 1 (my COMMENT at 5bcb565) the production file superset/utils/machine_auth.py is byte-identical (sha256 49d7c9da… at 5bcb565, bb15e94, and the current head 1e4a1bc), so round-1's verdicts stand and are not repeated here. 1e4a1bc is a pure master→patch-4 merge (parents bb15e94 + ac3c158); the authored diff across it is empty, so it introduces no semantic conflict in either authored file. That leaves exactly one previously-unreviewed change: the new test in machine_auth_tests.py. This review covers only that.

The new timeout test is genuinely coupled, not vacuous. test_authenticate_browser_context_sets_cookies_after_navigation_timeout injects mock_page.goto.side_effect = PlaywrightTimeout(...). Reverting only the production try/except PlaywrightTimeout (leaving a bare page.goto) makes the exception propagate out of authenticate_browser_context, so the result = provider.authenticate_browser_context(...) line raises before any assertion and the test goes RED. It therefore locks the exact behavior the PR adds. (Verified analytically by revert-reasoning; the integration harness is not runnable in my environment — /health is down — so I did not execute it. An environmental inability to run is not a PR defect.) The assertions are substantive, not identity checks: beyond "did not raise," it asserts add_cookies fired with the patched session=abc123 value (the real cookie-installation data path) and that clear_cookies fired. Importing PlaywrightTimeout from the module under test (not from playwright directly) is the right call — the raised type equals the caught type whether or not playwright is installed.

Security check (this file propagates session cookies into a screenshot browser context): no weaker guarantee, no leak. The test asserts that a navigation timeout still installs auth cookies, which reads like "a failure path grants auth" — but the auth is not derived from the navigation. get_auth_cookies(user) performs a server-side login_user(user) and harvests that user's own session cookie; add_cookies then installs it with an explicit domain=url.netloc, independent of whether page.goto("/login/") committed. The timeout affects only page render, not cookie derivation, so the timeout path produces the same auth state as the success path — for the same user, with no privilege change. clear_cookies() runs unconditionally before add_cookies(), so no cross-context residue is introduced on either path. The behavior the test pins is the strictly stronger one: a slow/failed login-page render must not abort authentication (the pre-PR behavior would have left an unauthenticated context and risked a login-page screenshot — the worse outcome, and the same class the sibling report-screenshot PRs hardened). This is intended and safe.

Prior bot finding addressed: bito's inline note (test-file thread, now resolved) flagged the missing clear_cookies assertion; the "Verify cookies" commit added exactly that. Confirmed present at head.

No blocking findings and nothing new to change. Non-blocking nit (optional, not tracked): neither this test nor the existing happy-path test asserts the cookie's domain field, which is the property that makes the fall-through safe — an explicit domain == url.netloc assertion would document that invariant, but its absence is a pre-existing convention, not a regression from this delta.

@rusackas

Copy link
Copy Markdown
Member

Nice catch, and the fix matches what the rest of the screenshot flow already does with SCREENSHOT_PLAYWRIGHT_WAIT_EVENT. It's picked up a merge conflict against master now though — rebase it and we'll get this in.

@rusackas

Copy link
Copy Markdown
Member

Thanks for tracking this down, the timeout handling and the matching test look solid. Only blocker is master has moved on and this now conflicts. I'll see if I can rebase it, but feel free to do the same if you still see conflicts.

@rusackas

Copy link
Copy Markdown
Member

Heya @kakoni, #44109 pulled the page.goto() priming navigation this adds wait_until to entirely, since that page staying open on the shared context was what let a late anonymous Set-Cookie clobber the injected auth cookie. Re-adding it with a timeout wouldn't fix that, so closing as superseded. Holler if you're still seeing the underlying timeout somewhere else.

@rusackas rusackas closed this Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires:rebase Requires rebasing on top of current master size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants