Skip to content
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

Enhance tables_involved Property to Include Tables from Update and Delete Operations #717

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

emregeldegul
Copy link
Contributor

@emregeldegul emregeldegul commented Jun 21, 2024

This pull request addresses the issue where the tables_involved property of the SQLQuery model fails to recognize tables involved in UPDATE operation. The current implementation only captures tables involved in SELECT and JOIN operations.

The updated implementation includes UPDATE operation to ensure comprehensive table identification. The modified code is as follows:

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"
                or component.lower() == "update"
            ):
                ...
        return tables

By including update statement, this change ensures that all relevant tables are captured for a more complete SQL query analysis. This update helps in better tracking and debugging of SQL queries within Django applications.

Fixes #716

… operation

- Enhanced the `tables_involved` property of the `SQLQuery` model to correctly identify tables involved in `UPDATE` operation.
- Added new test cases to validate the changes:
  - Test for `UPDATE` queries.
  - Test for complex `UPDATE` query involving subqueries and joins.
  - Ensured existing tests for `SELECT`, `JOIN`, and `AS` tokens continue to pass.
@albertyw albertyw merged commit e8e7d46 into jazzband:master Aug 15, 2024
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect (Blank) Table Identification in SQL Queries for Update Operation
2 participants