Skip to content

Commit

Permalink
fix: check length of args of python model function before accessing it (
Browse files Browse the repository at this point in the history
#6042)

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

* Add test

* changie
  • Loading branch information
chamini2 authored Oct 11, 2022
1 parent 85e415f commit dcd6ef7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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:
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

0 comments on commit dcd6ef7

Please sign in to comment.