korbit-ai[bot] commented on code in PR #32175:
URL: https://github.com/apache/superset/pull/32175#discussion_r1945566562


##########
superset/jinja_context.py:
##########
@@ -596,12 +596,24 @@ def process_template(self, sql: str, **kwargs: Any) -> 
str:
         >>> sql = "SELECT '{{ datetime(2017, 1, 1).isoformat() }}'"
         >>> process_template(sql)
         "SELECT '2017-01-01T00:00:00'"
+        This function will attempt to resolve nested Jinja expressions
+        up to 4 iterations.
         """
-        template = self.env.from_string(sql)
+        # Initialize the rendered SQL with the original SQL string.
+        rendered_sql = sql
         kwargs.update(self._context)
-
         context = validate_template_context(self.engine, kwargs)
-        return template.render(context)
+
+        # Render recursively up to 4 levels.
+        for _i in range(4):

Review Comment:
   ### Fixed Iteration Limit May Be Insufficient <sub>![category 
Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The hardcoded limit of 4 iterations may be insufficient for deeply nested 
expressions that require more resolution steps.
   
   ###### Why this matters
   Users may have valid use cases requiring more than 4 levels of nesting, 
leading to incompletely resolved templates.
   
   ###### Suggested change ∙ *Feature Preview*
   Make the iteration limit configurable and add validation:
   ```python
   MAX_TEMPLATE_RESOLUTION_ITERATIONS = 
current_app.config.get('MAX_TEMPLATE_RESOLUTION_ITERATIONS', 4)
   if MAX_TEMPLATE_RESOLUTION_ITERATIONS > 10:
       raise SupersetTemplateException('Maximum template resolution iterations 
cannot exceed 10')
   for _i in range(MAX_TEMPLATE_RESOLUTION_ITERATIONS):
       template = self.env.from_string(rendered_sql)
       rendered_sql = template.render(context)
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this 
comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e4a174ae-8701-45ed-9392-03642eb4f56b?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:4f70303e-dc4c-48f3-b94f-a5ecda10afc1 -->
   



-- 
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]

Reply via email to