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-3210] [Bug] Error using dbt list --select when there is a cross-project model that is version=0 in the parent project #8836

Closed
2 tasks done
graciegoheen opened this issue Oct 11, 2023 · 4 comments · Fixed by #8915 · May be fixed by #10437
Closed
2 tasks done
Assignees
Labels
backport 1.6.latest backport 1.7.latest bug Something isn't working High Severity bug with significant impact that should be resolved in a reasonable timeframe

Comments

@graciegoheen
Copy link
Contributor

graciegoheen commented Oct 11, 2023

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

When you attempt to reference a model version 0, you get a stack trace error.

Expected Behavior

We should allow you to set model version to be 0.

Steps To Reproduce

  1. On parent/hub project, add a versioned model with v: 0
  2. On the child/spoke project, attempt to reference that versioned model in a model:
    select * from {{ ref('example_hub', 'my_second_dbt_model', v=0) }}
  3. run dbt list --select anything

Outstanding question - is this only affecting cross-project refs? Or all refs to a model with v: 0?

Relevant log output

No response

Environment

- OS:
- Python:
- dbt:

Which database adapter are you using with dbt?

No response

Additional Context

No response

@graciegoheen graciegoheen added bug Something isn't working triage labels Oct 11, 2023
@github-actions github-actions bot changed the title [Bug] cannot set model version to be 0 [CT-3210] [Bug] cannot set model version to be 0 Oct 11, 2023
@graciegoheen graciegoheen added the High Severity bug with significant impact that should be resolved in a reasonable timeframe label Oct 11, 2023
@racheldaniel
Copy link
Contributor

Just a little bit more context-- not every dbt list will cause this error-- there has to be a selector in the command, as the error only happens if it gets to this check, and an * selector will return True from the conditional before it. Took us a bit to figure that one out 🙂

@dbeatty10
Copy link
Contributor

I was able to reproduce this error, but it was not restricted to models with version == 0, so I'm going to update the issue title. It was restricted to versioned models within the parent project though.

Here's the line of code that ultimately threw the error:

if fqn[-2] == node_selector:

Reprex

Parent project

dbt_project.yml

name: "my_parent_project"
...

models/dim_customers.sql

select 1 as id

models/_models.yml

models:
  - name: dim_customers
    access: public
    versions:
      - v: 1

Child project

models/child_dim_customers.sql

select * from {{ ref('my_parent_project', 'dim_customers') }}

Within the child project, try to do any selection with dbt list:

dbt list -s anything
23:02:42  Encountered an error:
list index out of range
Stacktrace
23:02:42  Encountered an error:
list index out of range
23:02:42  Traceback (most recent call last):
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/cli/requires.py", line 87, in wrapper
    result, success = func(*args, **kwargs)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/cli/requires.py", line 72, in wrapper
    return func(*args, **kwargs)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/cli/requires.py", line 143, in wrapper
    return func(*args, **kwargs)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/cli/requires.py", line 172, in wrapper
    return func(*args, **kwargs)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/cli/requires.py", line 219, in wrapper
    return func(*args, **kwargs)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/cli/requires.py", line 259, in wrapper
    return func(*args, **kwargs)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/cli/main.py", line 506, in list
    results = task.run()
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/task/list.py", line 139, in run
    return self.output_results(generator())
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/task/list.py", line 143, in output_results
    for result in results:
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/task/list.py", line 83, in generate_selectors
    for node in self._iterate_selected_nodes():
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/task/list.py", line 61, in _iterate_selected_nodes
    nodes = sorted(selector.get_selected(spec))
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 303, in get_selected
    selected_nodes, indirect_only = self.select_nodes(spec)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 158, in select_nodes
    direct_nodes, indirect_nodes = self.select_nodes_recursively(spec)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 130, in select_nodes_recursively
    bundles = [self.select_nodes_recursively(component) for component in spec]
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 130, in <listcomp>
    bundles = [self.select_nodes_recursively(component) for component in spec]
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 130, in select_nodes_recursively
    bundles = [self.select_nodes_recursively(component) for component in spec]
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 130, in <listcomp>
    bundles = [self.select_nodes_recursively(component) for component in spec]
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 130, in select_nodes_recursively
    bundles = [self.select_nodes_recursively(component) for component in spec]
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 130, in <listcomp>
    bundles = [self.select_nodes_recursively(component) for component in spec]
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 128, in select_nodes_recursively
    direct_nodes, indirect_nodes = self.get_nodes_from_criteria(spec)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 82, in get_nodes_from_criteria
    collected = self.select_included(nodes, spec)
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector.py", line 68, in select_included
    return set(method.search(included_nodes, spec.value))
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector_methods.py", line 215, in search
    if self.node_is_match(selector, real_node.fqn, real_node.is_versioned):
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector_methods.py", line 203, in node_is_match
    elif is_selected_node(unscoped_fqn, qualified_name, is_versioned):
  File "/Users/dbeatty/projects/environments/postgres_1.6/lib/python3.8/site-packages/dbt/graph/selector_methods.py", line 62, in is_selected_node
    if fqn[-2] == node_selector:
IndexError: list index out of range

@dbeatty10 dbeatty10 removed the triage label Oct 13, 2023
@dbeatty10 dbeatty10 changed the title [CT-3210] [Bug] cannot set model version to be 0 [CT-3210] [Bug] Error using dbt list --select when is a cross-project model that is versioned in the parent project Oct 13, 2023
@dbeatty10 dbeatty10 changed the title [CT-3210] [Bug] Error using dbt list --select when is a cross-project model that is versioned in the parent project [CT-3210] [Bug] Error using dbt list --select when there is a cross-project model that is versioned in the parent project Oct 13, 2023
@martynydbt martynydbt assigned aranke and unassigned QMalcolm Oct 25, 2023
@aranke
Copy link
Member

aranke commented Oct 26, 2023

Added a fix in #8915 for scenario where version == 0 (spoiler alert: if 0 evaluates to False).

@dbeatty10 I'm unable to reproduce the behavior for version == 1, it works fine on my machine 🙃
Can we pair on this later today to investigate?

@dbeatty10 dbeatty10 changed the title [CT-3210] [Bug] Error using dbt list --select when there is a cross-project model that is versioned in the parent project [CT-3210] [Bug] Error using dbt list --select when there is a cross-project model that is version=0 in the parent project Oct 26, 2023
@dbeatty10
Copy link
Contributor

@aranke and I just finished pairing on this.

Indeed, v: 1 did work just fine, and it was only v: 0 which triggered the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.6.latest backport 1.7.latest bug Something isn't working High Severity bug with significant impact that should be resolved in a reasonable timeframe
Projects
None yet
5 participants