-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template panel can trigger a SQL query #1834
Comments
As far as I understand the code should be something like this? try:
value_safe_repr = saferepr(value) # this MAY trigger a db query
...
else:
temp_layer[key] = value_safe_repr But I'm afraid of missing out details. |
In that case, you can directly assign it without the try:
temp_layer[key] = saferepr(value)
... I didn't submit a PR with such a change because it does change the output (for example additional quoting on a string) as the result is then processed by Current output is:
With the change, it would end up:
But this made me actually look at what In the end, what was triggering the SQL query was |
I've noticed this while working on #1833
When the template panel gets an object implementing
__repr__
, it might lead to triggering a SQL query:django-debug-toolbar/debug_toolbar/panels/templates/panel.py
Lines 120 to 132 in 199c2b3
The problem is that
saferepr(value)
is used for testing, whilevalue
is used for the actual assignment.For example, with
SimpleLazyObject
, the__repr__
returns<SimpleLazyObject: <function <lambda> at 0x7fe8ccb9dca0>>
, but latertemp_layer[key] = value
causes the query to be executed. This particular case will be addressed by #1833.Using
saferepr
was introduced in 06bafad via #1076 to address other side effects of evaluating.To make this code consistent, it should evaluate the value just once and use that later in the assignment.
The text was updated successfully, but these errors were encountered: