villebro opened a new pull request, #19585: URL: https://github.com/apache/superset/pull/19585
### SUMMARY Currently we are initializing the sandboxed Jinja environment with `undefined=DebugUndefined`, which causes the template to return the unrendered template if an undefined variable is referenced. This is both confusing and will seldom be very helpful, as the majority of jinja templates will generate invalid values when left unrendered. This PR changes the following: - Replace `DebugUndefined` with `StrictUndefined` to ensure that referencing undefined objects in jinja code results in an error rather than silently failing and leaving the template unrendered. An integration test is added to check for this behavior (see `test_get_template_undefined`). - Replace references to Jinja specific `TemplateException` with `SupersetTemplateException` to decouple templating from Jinja - add `try-except` blocks to all places in SQLA model where we call `BaseTemplateProcessor.process_template` to ensure that they are recast to `QueryObjectValidationError`. This will ensure the user gets a 400 rather than a 500. - refactor Jinja tests by separating into integration and unit tests and converting to functional tests ### AFTER Now referencing an undefined object results in an error rather than silently failing <img width="1179" alt="image" src="https://user-images.githubusercontent.com/33317356/162192014-ef7579ed-cf63-4507-80dc-69022404c501.png"> ### BEFORE Rendering the template silently failed, returning the unrendered template: <img width="1177" alt="image" src="https://user-images.githubusercontent.com/33317356/162192241-db88082b-6415-4da4-a90e-5342116f64be.png"> ### TESTING INSTRUCTIONS <!--- Required! What steps can be taken to manually verify the changes? --> ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [ ] Has associated issue: - [ ] 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 -- 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]
