Skip to content

fix: extract tables from jinja #34307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

justinpark
Copy link
Member

SUMMARY

When running a query containing Jinja templates in SQL Lab, Airbnb uses the extract_tables_from_jinja_sql function to check permissions on the tables used in the query. However, if the template string includes undeclared variables, these are replaced with blanks, which can cause syntax errors.

Screenshot 2025-07-24 at 3 52 00 PM

This issue has been addressed in the current master branch with an improved parsing logic.
This commit updates only the relevant changes that were not included in version 5.0 of this logic.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No error thrown

TESTING INSTRUCTIONS

Please design your security manager using extract_tables_from_jinja_sql and then run the following query

select * from table1 where column1 = {{ var1 }}

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

@justinpark justinpark requested review from betodealmeida and michael-s-molina and removed request for betodealmeida July 24, 2025 23:08
@dosubot dosubot bot added the global:jinja Related to Jinja templating label Jul 24, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

I've completed my review and didn't find any issues.

Files scanned
File Path Reviewed
superset/sql_parse.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Copy link

codecov bot commented Jul 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (5.0@fb035f4). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff           @@
##             5.0   #34307   +/-   ##
======================================
  Coverage       ?   83.24%           
======================================
  Files          ?      547           
  Lines          ?    39953           
  Branches       ?        0           
======================================
  Hits           ?    33258           
  Misses         ?     6695           
  Partials       ?        0           
Flag Coverage Δ
hive 47.85% <100.00%> (?)
mysql 74.51% <100.00%> (?)
postgres 74.57% <100.00%> (?)
presto 52.33% <100.00%> (?)
python 83.24% <100.00%> (?)
sqlite 74.09% <100.00%> (?)
unit 61.41% <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.

@michael-s-molina michael-s-molina merged commit 5eb61ec into apache:5.0 Jul 25, 2025
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
global:jinja Related to Jinja templating size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants