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

fix: check length of args of python model function before accessing it #6042

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20221011-160715.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: check length of args of python model function before accessing it
time: 2022-10-11T16:07:15.464093-04:00
custom:
Author: chamini2
Issue: "6041"
PR: "6042"
2 changes: 1 addition & 1 deletion core/dbt/parser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
if node.name == "model":
self.num_model_def += 1
if not node.args.args[0].arg == "dbt":
if node.args.args and not node.args.args[0].arg == "dbt":
self.dbt_errors.append("'dbt' not provided for model as the first argument")
if len(node.args.args) != 2:
chamini2 marked this conversation as resolved.
Show resolved Hide resolved
self.dbt_errors.append(
Expand Down
12 changes: 11 additions & 1 deletion test/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,17 @@ def model(dbt):
self.parser.manifest.files[block.file.file_id] = block.file
with self.assertRaises(ParsingException):
self.parser.parse_file(block)


def test_wrong_python_model_def_miss_session(self):
py_code = """
def model():
return df
"""
block = self.file_block_for(py_code, 'nested/py_model.py')
self.parser.manifest.files[block.file.file_id] = block.file
with self.assertRaises(ParsingException):
self.parser.parse_file(block)

def test_wrong_python_model_def_wrong_arg(self):
""" First argument for python model should be dbt
"""
Expand Down