Skip to content

Conversation

@dpgaspar
Copy link
Member

@dpgaspar dpgaspar commented Jan 7, 2026

SUMMARY

Streaming CSV exports create a new Flask app context when the generator runs, which causes flask.g attributes from the original request to be lost. This can break functionality that relies on request-scoped data stored in g.

This fix:

  1. Captures all flask.g attributes when the command is initialized (during the original request context)
  2. Restores them via preserve_g_context() when the generator executes in the new app context

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A - backend change

TESTING INSTRUCTIONS

  1. Run existing tests: pytest tests/unit_tests/commands/sql_lab/streaming_export_command_test.py -v
  2. All 16 tests should pass

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

@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@dosubot dosubot bot added the change:backend Requires changing the backend label Jan 7, 2026
@codeant-ai-for-open-source
Copy link
Contributor

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Context restore semantics
    preserve_g_context sets attributes on g and then deletes them in the finally block. If the target app context already had attributes with the same keys, they will be overwritten and then removed, potentially losing original values. The context manager should preserve and restore previous values (or avoid deleting pre-existing attributes).

  • g capture method
    Capturing attributes via dir(g) and getattr(g, key) may pick up class attributes, descriptors, callables, or attributes that raise on access. This can cause unexpected behavior or exceptions during capture and may include non-instance data that should not be copied to the streaming context. Consider using the g instance dict (e.g. g.__dict__) or defensive access to only copy user-set attributes.

  • Capture timing / staleness
    The code captures g attributes in __init__. If the command object is constructed outside the request/app context (or long before run() is called), the captured data may be empty or stale. Capture request-scoped state at the time run() is invoked (or immediately before starting the streaming generator).

@netlify
Copy link

netlify bot commented Jan 7, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 37119f9
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/695e49b1b3c15a0008180d16
😎 Deploy Preview https://deploy-preview-36950--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI finished reviewing your PR.

Copy link
Contributor

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #65a420

Actionable Suggestions - 1
  • superset/commands/streaming_export/base.py - 1
Review Details
  • Files reviewed - 1 · Commit Range: 37119f9..37119f9
    • superset/commands/streaming_export/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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 23.52941% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.17%. Comparing base (2080633) to head (cf3d135).
⚠️ Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/streaming_export/base.py 23.52% 13 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #36950       +/-   ##
===========================================
+ Coverage        0   68.17%   +68.17%     
===========================================
  Files           0      639      +639     
  Lines           0    47665    +47665     
  Branches        0     5205     +5205     
===========================================
+ Hits            0    32494    +32494     
- Misses          0    13891    +13891     
- Partials        0     1280     +1280     
Flag Coverage Δ
hive 43.09% <23.52%> (?)
mysql 66.17% <23.52%> (?)
postgres 66.22% <23.52%> (?)
presto 46.69% <23.52%> (?)
python 68.14% <23.52%> (?)
sqlite 65.94% <23.52%> (?)
unit 100.00% <ø> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

dpgaspar and others added 2 commits January 7, 2026 12:17
The app context is discarded after the generator finishes, so cleaning
up g attributes is unnecessary.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Capture flask.g attributes right before creating the generator rather
than at command construction time. This is closer to when we actually
need the data and avoids holding onto g state longer than necessary.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@dpgaspar dpgaspar force-pushed the fix/upstream-streaming-export branch from 3d4cf23 to cf3d135 Compare January 7, 2026 12:20
@dpgaspar dpgaspar requested a review from geido January 7, 2026 12:22
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Jan 7, 2026

Code Review Agent Run #8fd3f4

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 37119f9..cf3d135
    • superset/commands/streaming_export/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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Contributor

@amaannawab923 amaannawab923 left a comment

Choose a reason for hiding this comment

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

Thanks ! LGTM !

@dpgaspar dpgaspar merged commit a6d85dc into apache:master Jan 8, 2026
65 checks passed
@dpgaspar dpgaspar deleted the fix/upstream-streaming-export branch January 8, 2026 16:11
JCelento pushed a commit to JCelento/superset that referenced this pull request Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.0:checkpoint change:backend Requires changing the backend size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants