jazzband / django-silk

Silky smooth profiling for Django
MIT License
4.32k stars 332 forks source link

Incorrect (Blank) Table Identification in SQL Queries for Update Operation #716

Open emregeldegul opened 2 weeks ago

emregeldegul commented 2 weeks ago

I have encountered an issue with the tables_involved property of the SQLQuery model. Currently, this property only identifies tables involved in SELECT and JOIN operations. However, it fails to recognize tables involved in UPDATE operation.

The existing implementation:

class SQLQuery(models.Model):
    query = TextField()
    ...

    @property
    def tables_involved(self):
        ...
        for idx, component in enumerate(components):
            ...
            if component.lower() == 'from' or component.lower() == 'join' or component.lower() == 'as':
                ...
        return tables

As a result, it is not accurately capturing tables involved in UPDATE queries. This limits the utility of the tables_involved property for comprehensive SQL analysis.

I will create a pull request for this.

Honestly, is the UPDATE query useful for analysis? I'm not sure. However, it doesn't hurt to have the 'table name' field full when showing the UPDATE query.