LevisNgigi opened a new pull request, #35009: URL: https://github.com/apache/superset/pull/35009
## **User description** <!--- fix(sql): handle undefined template variables safely in query rendering --> ### SUMMARY This PR fixes a bug in SQL template processing when the `ENABLE_TEMPLATE_PROCESSING` feature flag is enabled.It handles undefined template variables gracefully by falling back to the original SQL. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF AFTER <img width="2560" height="1440" alt="template_processing" src="https://github.com/user-attachments/assets/941f36d8-12eb-4387-b0d4-b1408ddebb91" /> ### TESTING INSTRUCTIONS Go to SQL Lab Use the following query: with ws1 as ( select 1 as one ) select * from ws1 --{{ ref('value_date_delinquent_dates')|length }} Run query It should run successfully with no errors ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [ x] Has associated issue: Fixes #32044 - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] 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 Description** Avoid query failures from undefined template functions and ignore template tags in comments ### What Changed - If a Jinja template uses an undefined function-like identifier, the query now runs using the original SQL instead of erroring. - Template validation ignores Jinja-like tokens inside SQL comments so queries with commented template fragments no longer trigger undefined-parameter errors. - Template errors for undefined function-like identifiers are classified distinctly so they are handled by the fallback behavior. ### Impact `✅ Fewer failed queries in SQL Lab when a template function is missing` `✅ Fewer false "undefined parameter" errors from commented template code` `✅ Clearer handling of template function errors` <details> <summary><strong>💡 Usage Guide</strong></summary> ### Checking Your Pull Request Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later. ### Talking to CodeAnt AI Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask: <pre> <code>@codeant-ai ask: Your question here</code> </pre> This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code. #### Example <pre> <code>@codeant-ai ask: Can you suggest a safer alternative to storing this secret?</code> </pre> ### Preserve Org Learnings with CodeAnt You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input: <pre> <code>@codeant-ai: Your feedback here</code> </pre> This helps CodeAnt AI learn and adapt to your team's coding style and standards. #### Example <pre> <code>@codeant-ai: Do not flag unused imports.</code> </pre> ### Retrigger review Ask CodeAnt AI to review the PR again, by typing: <pre> <code>@codeant-ai: review</code> </pre> ### Check Your Repository Health To analyze the health of your code repository, visit our dashboard at [https://app.codeant.ai](https://app.codeant.ai). This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health. </details> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
