Skip to content

Conversation

yakovlevvs
Copy link

Resolves #11363

Problem

When model name contains dots, partial parsing fails with dbt found two schema.yml entries for the same resource named error.

Solution

Fixed a function which causes incorrect manifest parsing for this case.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@yakovlevvs yakovlevvs requested a review from a team as a code owner April 2, 2025 20:32
@cla-bot cla-bot bot added the cla:yes label Apr 2, 2025
@github-actions github-actions bot added the community This PR is from a community member label Apr 2, 2025
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.84%. Comparing base (359b195) to head (ed8adbf).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11455      +/-   ##
==========================================
- Coverage   88.90%   88.84%   -0.06%     
==========================================
  Files         194      194              
  Lines       24509    24514       +5     
==========================================
- Hits        21789    21779      -10     
- Misses       2720     2735      +15     
Flag Coverage Δ
integration 85.83% <100.00%> (-0.14%) ⬇️
unit 62.72% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.72% <50.00%> (-0.02%) ⬇️
Integration Tests 85.83% <100.00%> (-0.14%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@dbeatty10 dbeatty10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yakovlevvs Thanks again for opening this PR!

There are a few failing tests:

  • pytest tests/functional/partial_parsing/test_versioned_models.py::TestVersionedModels::test_pp_versioned_models
  • pytest tests/functional/defer_state/test_modified_state.py::TestModifiedLatestVersion::test_changed_access
  • pytest tests/functional/unit_testing/test_ut_versions.py::TestVersions::test_versions

If you define a versioned model and examine the target/manifest.json, you'll see why -- versioned models have at least 3 dot separators (more if the model name contains dots):

        "model.my_project.my_model.v2": {
            "database": "db",
            "schema": "dev",
            "name": "my_model",
            "resource_type": "model",
            "package_name": "my_project",
            "path": "my_model_v2.sql",
            "original_file_path": "models/my_model_v2.sql",
            "unique_id": "model.my_project.my_model.v2",

So the assumption that there's a max of 2 dots doesn't hold.

Quite the puzzle to try to figure out how to handle all of these cases! Do you have any ideas?

@dbeatty10
Copy link
Contributor

@yakovlevvs Here's (3) simple project files for versioned models that you can use for local testing:

models/my_model_v1.sql

select 1 as id

models/my_model_v2.sql

select 1 as id

models/_models.yml

models:
  - name: my_model
    latest_version: 1
    versions:
      - v: 1
      - v: 2

@yakovlevvs
Copy link
Author

Hello @dbeatty10 yes, I've also noticed that from tests. Unfortunately it is not easy to say if the id of patched_node contains version of the model or not.
I think we could get a pattern of matching unique_id from elem dictionary, something like this:

prefix = key_to_prefix[dict_key]
model_prefix = "{}.{}.".format(prefix, schema_file.project_name)
elem_unique_ids = []
for unique_id in schema_file.node_patches:
    if not unique_id.startswith(prefix):
        continue
    if prefix == "model":
        if (unique_id == model_prefix + elem["name"] or 
                ("versions" in elem and 
                unique_id.startswith(model_prefix + elem["name"] + '.v'))):
            elem_unique_ids.append(unique_id)
    else:
        parts = unique_id.split(".")
        elem_name = parts[2]
        if elem_name == elem["name"]:
            elem_unique_ids.append(unique_id)

I will test this idea locally and if it works, I will fix it in new commit a bit later

@yakovlevvs
Copy link
Author

Hello @dbeatty10 i've pushed a new commit. With this fix all tests pass for me locally. I've also tested this on my enterprise's schema - partial parsing works fine for both versioned and unversioned models with and without dots. Could you please trigger the tests again?

@yakovlevvs yakovlevvs requested a review from dbeatty10 April 9, 2025 08:20
@yakovlevvs
Copy link
Author

Hello @dbeatty10 it seems like all unit and functional tests passed successfully but "Validate Additional Reviews" is stuck forever. Is there anything I can do about this or should I just wait for the review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes community This PR is from a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] partial parse fails when schema file is updated
2 participants