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

Sweep: Execute dbt SQL fails if the query starts with a Jinga comment #1158

Closed

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented May 23, 2024

Description

This pull request addresses an issue where executing dbt SQL statements that begin with a Jinja comment causes failures. It introduces a fix by stripping leading Jinja comments from the SQL statement before execution.

Summary

  • Added an import for the re module in dbt_core_integration.py to utilize regular expressions for processing SQL statements.
  • Implemented a new step in the execute_sql method to remove Jinja comments from the start of the SQL statement. This ensures that SQL queries starting with Jinja comments are executed without errors.
  • The change is made within the execute_sql function of the dbt_core_integration.py file, enhancing its robustness in handling SQL queries with Jinja syntax.

Fixes #1156.


💡 To get Sweep to edit this pull request, you can:

  • Comment below, and Sweep can edit the entire PR
  • Comment on a file, Sweep will only modify the commented file
  • Edit the original issue to get Sweep to recreate the PR from scratch

This is an automated message generated by Sweep AI.

Copy link
Contributor Author

sweep-ai bot commented May 23, 2024

Rollback Files For Sweep

  • Rollback changes to dbt_core_integration.py

This is an automated message generated by Sweep AI.

Copy link
Contributor Author

sweep-ai bot commented May 23, 2024

Sweep: PR Review

Authors of pull request: @sweep-ai[bot]

dbt_core_integration.py

Added the re module import and implemented a regex substitution to strip leading Jinja comments in the execute_sql method.

Sweep Found These Issues

  • The regex substitution to strip leading Jinja comments may inadvertently remove valid SQL content if the regex pattern is not precise enough.
  • def execute_sql(self, raw_sql: str) -> DbtAdapterExecutionResult:
    """Execute dbt SQL statement against database"""
    with self.adapter.connection_named("master"):
    # Strip leading Jinja comments
    raw_sql = re.sub(r'^{#.*#}\s*', '', raw_sql, flags=re.MULTILINE)

    View Diff


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Execute dbt SQL fails if the query starts with a Jinga comment
1 participant