korbit-ai[bot] commented on code in PR #33596:
URL: https://github.com/apache/superset/pull/33596#discussion_r2109984773
##########
superset/jinja_context.py:
##########
@@ -641,6 +641,12 @@ def set_context(self, **kwargs: Any) -> None:
self._context.update(kwargs)
self._context.update(context_addons())
+ def get_context(self) -> dict[str, Any]:
+ """
+ Returns the current template context.
+ """
+ return self._context
Review Comment:
### Exposed Mutable Internal State <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
Direct access to internal state (_context) without protecting against
potential dictionary mutations
###### Why this matters
Returning the internal dictionary directly allows callers to modify the
template context without going through proper channels, potentially leading to
unexpected behavior.
###### Suggested change ∙ *Feature Preview*
Return a copy of the context dictionary to prevent external modifications:
```python
def get_context(self) -> dict[str, Any]:
"""
Returns the current template context.
"""
return self._context.copy()
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7fed0195-ae48-43b0-947f-c3f161850dfe/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7fed0195-ae48-43b0-947f-c3f161850dfe?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7fed0195-ae48-43b0-947f-c3f161850dfe?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7fed0195-ae48-43b0-947f-c3f161850dfe?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/7fed0195-ae48-43b0-947f-c3f161850dfe)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:3acc34b4-dab7-4262-b086-e64638878763 -->
[](3acc34b4-dab7-4262-b086-e64638878763)
--
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]