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

[CT-1326] [Bug] Python model with no arguments in the function raises index our of range exception #6041

Closed
2 tasks done
chamini2 opened this issue Oct 10, 2022 · 1 comment · Fixed by #6042
Closed
2 tasks done
Labels
bug Something isn't working python_models

Comments

@chamini2
Copy link
Contributor

chamini2 commented Oct 10, 2022

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

Creating a Python model with a model function without any arguments ends in an list index out of range exception rather than a helpful message.

def model():
  ...

Expected Behavior

It should give a helpful message about how Python model definitions should look.

Steps To Reproduce

  1. Write a Python model with no arguments in the function
def model():
  import pandas as pd
  return pd.DataFrame.from_dict({'a': [1,2,3], 'b': ['some', None, None]})
  1. dbt run

Relevant log output

def model(dbt):
    import pandas as pd


❯ dbt run
21:26:46  [WARNING]: Deprecated functionality
The `source-paths` config has been renamed to `model-paths`. Please update your
`dbt_project.yml` configuration to reflect this change.
21:26:46  [WARNING]: Deprecated functionality
The `data-paths` config has been renamed to `seed-paths`. Please update your
`dbt_project.yml` configuration to reflect this change.
21:26:46  Running with dbt=1.4.0-a1
21:26:46  Encountered an error:
Parsing Error in model model_c (models/staging/model_c.py)
  model function should have two args, `dbt` and a session to current warehouse


*****

def model():
    import pandas as pd

❯ dbt run
21:29:26  [WARNING]: Deprecated functionality
The `source-paths` config has been renamed to `model-paths`. Please update your
`dbt_project.yml` configuration to reflect this change.
21:29:26  [WARNING]: Deprecated functionality
The `data-paths` config has been renamed to `seed-paths`. Please update your
`dbt_project.yml` configuration to reflect this change.
21:29:26  Running with dbt=1.4.0-a1
21:29:27  Encountered an error:
list index out of range
21:29:27  Traceback (most recent call last):
  File ".../Projects/fal-ai/dbt-core/core/dbt/main.py", line 135, in main
    results, succeeded = handle_and_check(args)
  File ".../Projects/fal-ai/dbt-core/core/dbt/main.py", line 198, in handle_and_check
    task, res = run_from_args(parsed)
  File ".../Projects/fal-ai/dbt-core/core/dbt/main.py", line 245, in run_from_args
    results = task.run()
  File ".../Projects/fal-ai/dbt-core/core/dbt/task/runnable.py", line 453, in run
    self._runtime_initialize()
  File ".../Projects/fal-ai/dbt-core/core/dbt/task/runnable.py", line 161, in _runtime_initialize
    super()._runtime_initialize()
  File ".../Projects/fal-ai/dbt-core/core/dbt/task/runnable.py", line 94, in _runtime_initialize
    self.load_manifest()
  File ".../Projects/fal-ai/dbt-core/core/dbt/task/runnable.py", line 81, in load_manifest
    self.manifest = ManifestLoader.get_full_manifest(self.config)
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/manifest.py", line 219, in get_full_manifest
    manifest = loader.load()
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/manifest.py", line 349, in load
    self.parse_project(
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/manifest.py", line 477, in parse_project
    parser.parse_file(block)
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/base.py", line 414, in parse_file
    self.parse_node(file_block)
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/base.py", line 388, in parse_node
    self.render_update(node, config)
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/models.py", line 227, in render_update
    self.parse_python_model(node, config, context)
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/models.py", line 204, in parse_python_model
    dbtValidator.visit(tree)
  File ".../.pyenv/versions/3.8.13/lib/python3.8/ast.py", line 371, in visit
    return visitor(node)
  File ".../.pyenv/versions/3.8.13/lib/python3.8/ast.py", line 379, in generic_visit
    self.visit(item)
  File ".../.pyenv/versions/3.8.13/lib/python3.8/ast.py", line 371, in visit
    return visitor(node)
  File ".../Projects/fal-ai/dbt-core/core/dbt/parser/models.py", line 52, in visit_FunctionDef
    if not node.args.args[0].arg == "dbt":
IndexError: list index out of range

Environment

- OS: macOS 12.6
- Python: Python 3.8.13
- dbt:
  Core:
    - installed: 1.4.0-a1
    - latest:    1.2.2    - Ahead of latest version!

Which database adapter are you using with dbt?

postgres

Additional Context

No response

@chamini2 chamini2 added bug Something isn't working triage labels Oct 10, 2022
@github-actions github-actions bot changed the title [Bug] <title> [CT-1326] [Bug] <title> Oct 10, 2022
@chamini2 chamini2 changed the title [CT-1326] [Bug] <title> [CT-1326] [Bug] Python model with no arguments in the function raises index our of range exception Oct 10, 2022
@dbeatty10
Copy link
Contributor

Thanks for reporting this @chamini2! And thanks for already starting on a proposed solution in #6042 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python_models
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants