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-1197] [Bug] Schema Files not parsed for models at the right time #5869

Closed
2 tasks done
emmyoop opened this issue Sep 16, 2022 · 2 comments
Closed
2 tasks done

[CT-1197] [Bug] Schema Files not parsed for models at the right time #5869

emmyoop opened this issue Sep 16, 2022 · 2 comments
Labels
bug Something isn't working tech_debt Behind-the-scenes changes, with little direct impact on end-user functionality

Comments

@emmyoop
Copy link
Member

emmyoop commented Sep 16, 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

When we parse a model node, any configs set in the schema yaml file do not get incorporated until after the fact.

Specifically all nodes are considered enabled (if only disabled in the schema yaml file) while we parse through the sql files until we parse the schema file. So they end up as nodes in the manifest to be processed and are not in the disabled dict.

Specifically the value of node.config.enabled will always be True when the node was set to disabled only in the yaml file. It will probably be incorrectly set to False if it is set to False at the project level and overridden at the yaml level to be True.

def add_result_node(self, block: FileBlock, node: ManifestNodes):
if node.config.enabled:
self.manifest.add_node(block.file, node)
else:
self.manifest.add_disabled(block.file, node)

There is also a bit of hacky logic as follows to ensure we don't resolve refs on disabled nodes even though the node is in the manifest.

TODO: add link to process_refs in parser/manifest.py after #5868 gets merged

            # if the node is disabled, no need to resolve the refs
            if node.config.enabled:
                _process_refs_for_node(self.manifest, current_project, node)

The above conditional should be removed when this gets resolved since we would no longer be resolving refs for disabled nodes.

Expected Behavior

Account for configs set in schema files.

Steps To Reproduce

A barebones project with 3 models:

-- my_model.sql
select 1 as user

-- my_model_2.sql
select * from {{ ref('my_model') }}

-- my_model_3.sql
select * from {{ ref('my_model_2') }}

A schema.yml like so:

version: 2
models:
  - name: my_model
  - name: my_model_2
    config:
      enabled: false
  - name: my_model_3
    config:
      enabled: false

run dbt run and examine manifest.nodes and manifest.disabled

Additional Context

#5868 fixed the bugs users are experiencing, this is to fix the underlying issue

@emmyoop emmyoop added bug Something isn't working triage labels Sep 16, 2022
@github-actions github-actions bot changed the title [Bug] Schema Files not parsed for models [CT-1197] [Bug] Schema Files not parsed for models Sep 16, 2022
@emmyoop emmyoop changed the title [CT-1197] [Bug] Schema Files not parsed for models [CT-1197] [Bug] Schema Files not parsed for models in time Sep 16, 2022
@emmyoop emmyoop changed the title [CT-1197] [Bug] Schema Files not parsed for models in time [CT-1197] [Bug] Schema Files not parsed for models at the right time Sep 16, 2022
@jtcohen6
Copy link
Contributor

@emmyoop Thanks for the thorough writeup!

The fundamental issue in the parsing order that you've identified here feels related to #4000 as well. We instantiate snapshot nodes after parsing the .sql file, perform dataclass validation, check for specific configs, if they're not supplied we raise an error, before actually parsing the .yml file that might contain those configs.

@leahwicz leahwicz added the tech_debt Behind-the-scenes changes, with little direct impact on end-user functionality label Sep 22, 2022
@emmyoop
Copy link
Member Author

emmyoop commented Oct 7, 2022

This really comes down to the order we have to process the files. "Fixing" this really means reworking parsing order, possibly saving files to parse over again? Not sure if it would really decrease complexity because we re-process the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tech_debt Behind-the-scenes changes, with little direct impact on end-user functionality
Projects
None yet
Development

No branches or pull requests

4 participants