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

Allow variables with dot in sqlfluff:templater:python:context #5871

Open
3 tasks done
timchurch opened this issue May 13, 2024 · 0 comments · May be fixed by #5872
Open
3 tasks done

Allow variables with dot in sqlfluff:templater:python:context #5871

timchurch opened this issue May 13, 2024 · 0 comments · May be fixed by #5872
Labels
enhancement New feature or request

Comments

@timchurch
Copy link
Contributor

Search before asking

  • I searched the issues and found no similar issues.

Description

SQLFluff python templater does not currently support variables that contain a dot - e.g. {foo.bar}

This SQL:

SELECT * FROM {foo.bar}

..with this config:

[sqlfluff:templater:python:context]
foo.bar = foobar

..raises this error:

sqlfluff.core.errors.SQLTemplaterError: Failure in Python templating: 'foo'. Have you configured your variables? https://docs.sqlfluff.com/en/stable/configuration.html#python-templater

Related tickets (but for Jinja templater):

Use case

Python format strings support variables that use dot notation for object attribute access. This is a valid Python example that is not yet supported by SQLFluff:

class MyObject:
    bar = "blah"


sql = "SELECT * FROM {foo.bar}"
context = {"foo": MyObject()}
print(sql.format(**context))

Dialect

This is not dialect specific.

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

@timchurch timchurch added the enhancement New feature or request label May 13, 2024
@timchurch timchurch linked a pull request May 13, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant