-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[CT-2321] [Bug] error using inline compile with newline characters in jinja strings #7207
Comments
Thanks for trying this out and reporting this bug @dave-connors-3 🙌 |
Hmm, I'm not sure if this is actually a -- models/any_model.sql
select {{\n dbt_utils.group_by(5) \n}}
|
@jtcohen6 do you happen to know why it has an unexpected char of I'm wondering if knowing that answer might unlock the details of why this one weird trick works:
Could also be unrelated. |
Offhand, I'm not sure! |
@jtcohen6 -- is there something different about actually having |
Ahh - I wonder if this has to do with encoding! When we read files, we expect to decode them from UTF-8: dbt-core/core/dbt/clients/system.py Line 98 in 73ff497
I don't see us doing that for ipdb> self.args.inline
'select {{\\n dbt_utils.group_by(5) \\n}}'
ipdb> self.args.inline.encode("utf-8")
b'select {{\\n dbt_utils.group_by(5) \\n}}'
ipdb> self.args.inline.encode("utf-8").decode("utf-8")
'select {{\\n dbt_utils.group_by(5) \\n}}' Is this why we required that SQL inputs for I wonder if there's a way we can handle this within |
So - I think we need to do this before the v1.5 RC! Two options:
Especially now that we're supporting a programmatic interface to import base64
from dbt.cli.main import dbtRunner
my_query_with_newlines = """
{{
dbt_utils.group_by(5)
}}
"""
my_query_b64 = base64.b64encode(my_query_with_newlines.encode('utf-8'))
dbt = dbtRunner()
results, success = dbt.invoke(['compile', '--inline', my_query_b64]) |
@jtcohen6 I managed to fix this and add a test to my PR, so this should be resolved soon 😄 |
@aranke nice!! that's even better :) |
Is this a new bug in dbt-core?
Current Behavior
When passing raw SQL to the new
dbt compile --inline
command, the compiler does not properly handle newline characters within jinja blocks:Without newline characters:
With newline characters:
Same SQL written in a model file with the newlines:
Expected Behavior
New lines should not affect the jinja rendering!
Steps To Reproduce
dbt compile --inline
, see rendered sql{{ }}
, see errordbt compile -s model_name
see same result as step 1Relevant log output
No response
Environment
Which database adapter are you using with dbt?
postgres
Additional Context
No response
The text was updated successfully, but these errors were encountered: