Skip to content

Template panel can trigger a SQL query #1834

Closed
@nijel

Description

@nijel

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, 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions