You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that saferepr(value) is used for testing, while value is used for the actual assignment.
For example, with SimpleLazyObject, the __repr__ returns <SimpleLazyObject: <function <lambda> at 0x7fe8ccb9dca0>>, but later temp_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:
In that case, you can directly assign it without the else block:
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 pformat.
Current output is:
{'key': 'value'}
With the change, it would end up:
{'key': "'value'"}
But this made me actually look at what saferepr and pformat do, and they are doing almost the same thing, if one of them doesn't trigger evaluation, the other should neither.
In the end, what was triggering the SQL query was isinstance because that forces evaluation of the lazy object. This special case is covered by #1833, so I think this issue can be closes as there is nothing actually wrong with the referenced code.
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:https://github.com/jazzband/django-debug-toolbar/blob/199c2b3c6bc916d371bcfb11b0fcbbb690ee5e36/debug_toolbar/panels/templates/panel.py#L120-L132
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: