@@ -2841,6 +2841,84 @@ def fake_get_table_entity(table_fqn):
28412841 expected_fqn
28422842 ], f"Expected lineage to resolve via target_schema 'snapshots', got: { result } "
28432843
2844+ def test_dbt_entity_link_with_mixed_case_columns_issue_24636 (self ):
2845+ """
2846+ Test for issue #24636: dbt test case ingestion fails with relationship tests.
2847+
2848+ Root cause: dbt relationship tests have multiple upstream dependencies, but the
2849+ order varies by database engine (Snowflake first, Unity Catalog last). Previously,
2850+ code iterated over ALL upstream tables, causing column validation errors when
2851+ the referenced table didn't have the same column names.
2852+
2853+ Fix: Extract primary table from test_metadata.kwargs['model'] explicitly,
2854+ which is order-independent and works across all database engines.
2855+ """
2856+ _ , dbt_objects = self .get_dbt_object_files (
2857+ mock_manifest = MOCK_SAMPLE_MANIFEST_TEST_NODE
2858+ )
2859+
2860+ # Test case 1: Relationship test with kwargs['model'] extraction (main code path)
2861+ # This test exercises the primary fix for issue #24636
2862+ manifest_node = dbt_objects .dbt_manifest .nodes .get (
2863+ "test.jaffle_shop.relationships_un_rueckerstattungen_medis_base_PersonNr__ref_un_person_base_"
2864+ )
2865+ dbt_test = {
2866+ "manifest_node" : manifest_node ,
2867+ "upstream" : [
2868+ "unity.catalog.schema.un_rueckerstattungen_medis_base" , # Primary table
2869+ "unity.catalog.schema.un_person_base" , # Referenced table
2870+ ],
2871+ "results" : "" ,
2872+ }
2873+ result = generate_entity_link (dbt_test = dbt_test )
2874+ # Should return only one entity link (for the primary table)
2875+ self .assertEqual (
2876+ len (result ), 1 , "Should only create one entity link for primary table"
2877+ )
2878+ # Link should be to the primary table extracted from kwargs['model']
2879+ self .assertIn ("un_rueckerstattungen_medis_base" , result [0 ])
2880+ self .assertIn ("::columns::PersonNr>" , result [0 ])
2881+ self .assertNotIn ("un_person_base" , result [0 ])
2882+
2883+ # Test case 2: Verify kwargs['model'] path works with REVERSED upstream order
2884+ # This proves the fix is order-independent (the bug in #24636)
2885+ dbt_test_reversed = {
2886+ "manifest_node" : manifest_node ,
2887+ "upstream" : [
2888+ "unity.catalog.schema.un_person_base" , # Referenced table FIRST
2889+ "unity.catalog.schema.un_rueckerstattungen_medis_base" , # Primary table LAST
2890+ ],
2891+ "results" : "" ,
2892+ }
2893+ result_reversed = generate_entity_link (dbt_test = dbt_test_reversed )
2894+ # Should still return the primary table, proving kwargs['model'] extraction works
2895+ self .assertEqual (
2896+ len (result_reversed ),
2897+ 1 ,
2898+ "Should return primary table regardless of upstream order" ,
2899+ )
2900+ self .assertIn ("un_rueckerstattungen_medis_base" , result_reversed [0 ])
2901+ self .assertIn ("::columns::PersonNr>" , result_reversed [0 ])
2902+ self .assertNotIn ("un_person_base" , result_reversed [0 ])
2903+
2904+ # Test case 3: Fallback to first upstream when kwargs['model'] is unavailable
2905+ # This tests the fallback path (lines 720-722)
2906+ manifest_node_fallback = dbt_objects .dbt_manifest .nodes .get (
2907+ "test.jaffle_shop.unique_orders_order_id.fed79b3a6e"
2908+ )
2909+ dbt_test_fallback = {
2910+ "manifest_node" : manifest_node_fallback ,
2911+ "upstream" : [
2912+ "unity.catalog.schema.un_abrechnungsposition_cur" , # First table
2913+ "unity.catalog.schema.un_person_base" , # Second table
2914+ ],
2915+ "results" : "" ,
2916+ }
2917+ result_fallback = generate_entity_link (dbt_test = dbt_test_fallback )
2918+ # Should fall back to first upstream since model pattern doesn't match
2919+ self .assertEqual (len (result_fallback ), 1 )
2920+ self .assertIn ("un_abrechnungsposition_cur" , result_fallback [0 ])
2921+
28442922
28452923class TestDownloadDbtFiles (TestCase ):
28462924 """
0 commit comments