You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/04/07 11:54:11 UTC

[GitHub] [superset] villebro opened a new pull request, #19585: fix(jinja): raise exception on undefined value

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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] rusackas commented on pull request #19585: [WIP] fix(jinja): raise exception on undefined value

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #19585:
URL: https://github.com/apache/superset/pull/19585#issuecomment-1400811189

   Checking in (like with other aging WIP PRs) to see if there's intent to carry this forward. 🤞


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro closed pull request #19585: [WIP] fix(jinja): raise exception on undefined value

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro closed pull request #19585: [WIP] fix(jinja): raise exception on undefined value
URL: https://github.com/apache/superset/pull/19585


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org