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

handle exceptions that occur inside of jinja #935

Closed
drewbanin opened this issue Aug 15, 2018 · 3 comments
Closed

handle exceptions that occur inside of jinja #935

drewbanin opened this issue Aug 15, 2018 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@drewbanin
Copy link
Contributor

drewbanin commented Aug 15, 2018

Issue

Issue description

Given sql with invalid jinja like:

{{ config(
    materialized = "table",
    schema = 'custom_schema' -- render this in a custom schema
) }}

dbt will throw a very unhelpful error that looks like:

  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/dbt/parser/base_sql.py", line 95, in parse_sql_nodes
    macros=macros)
  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/dbt/parser/base.py", line 105, in parse_node
    capture_macros=True)
  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/dbt/clients/jinja.py", line 198, in get_rendered
    return render_template(template, ctx, node)
  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/dbt/clients/jinja.py", line 185, in render_template
    return template.render(ctx)
  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/Cellar/dbt/0.10.2/libexec/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: exceptions must derive from BaseException

It will likely be difficult to pinpoint the exact error, but it should ideally be able to throw some sort of human-readable parsing error, indicating the model where the syntax error occurred.

@drewbanin drewbanin added the bug Something isn't working label Aug 15, 2018
@drewbanin drewbanin added this to the Guion Bluford milestone Sep 18, 2018
@beckjake beckjake self-assigned this Oct 12, 2018
@beckjake
Copy link
Contributor

I can't reproduce this on any dbt versions, going back as far as 0.10.2. I consistently get this message:

Encountered an error:
Compilation Error in model bad (models/bad.sql)
  expected token ',', got 'this'
    line 3
      schema = 'custom_schema' -- render this in a custom schema

Which definitely isn't perfect, but seems pretty helpful to me. Is it possible this was fixed by a jinja update, or something like that?

I do recognize that stack trace as something I've seen in the past, and it's definitely unhelpful.

@drewbanin drewbanin added the wontfix Not a bug or out of scope for dbt-core label Oct 13, 2018
@drewbanin
Copy link
Contributor Author

Are you #wontfix-ing me???

Agreed, I just gave this a spin and couldn't reproduce it either. I didn't see anything in the Jinja changelog that seemed germane to this issue either. Going to close this, but will keep an eye out for this behavior in the wild.

@beckjake
Copy link
Contributor

Found a way to trigger this error! In a model that does not define thing: select * from {{ ref(thing + 'a') }}.
Python version 3.6 for this, I think 2.7 won't have the same issue.

@beckjake beckjake reopened this Oct 23, 2018
@beckjake beckjake removed the wontfix Not a bug or out of scope for dbt-core label Oct 23, 2018
beckjake added a commit that referenced this issue Oct 23, 2018
…cleanup

Handle undefined variables in jinja better (#935)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants