Skip to content

fix: sanitize hyphens in get_asset_key_str to prevent KeyError on hyphenated internal asset names#63

Open
connordouglashanna wants to merge 3 commits intoopensource-observer:mainfrom
connordouglashanna:fix/hyphenated-catalog-keyerror
Open

fix: sanitize hyphens in get_asset_key_str to prevent KeyError on hyphenated internal asset names#63
connordouglashanna wants to merge 3 commits intoopensource-observer:mainfrom
connordouglashanna:fix/hyphenated-catalog-keyerror

Conversation

@connordouglashanna
Copy link
Copy Markdown

@connordouglashanna connordouglashanna commented Apr 2, 2026

Howdy! I encountered a crash when attempting to add a SQLMesh pipeline that used a GCP project with a hyphen as the gateway, error message copied below. Fixes #62.

Comments indicated that the function get_asset_key_str() in translator.py:167 had been intended to normalize hyphens, but that the code to do so hadn't been added. The fix is one line and a test that target that function. The new test passes, but some other tests failed because of what looks like a preexisting bug with DuckDB on Windows.

Before the fix, @sqlmesh_assets passed hyphenated asset_outs and internal_asset_deps_map dicts to Dagster. Dagster's @multi_asset() function would then hand off the names to build_named_outs which normalized only the asset output names. The asset_deps don't get normalized by build_named_outs, retain their hyphens, and then fail to reconcile on decorator_assets_definition_builder.py:461. Dagster validation on line 443 of the same file checks the pre-normalization names and thus returns no error.

This is my first open source contribution! If you have any feedback on my code or anything else, please holler, I'm all ears! I considered whether there should maybe be a fix in Dagster too, but I don't know enough to say. I'd love to contribute there too if it's worth doing.

Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\myusername\Documents\my_project\dagster_defs.py", line 18, in <module> @sqlmesh_assets( ^^^^^^^^^^^^^^^ File "C:\Users\myusername\Documents\my_project\.venv\Lib\site-packages\dagster\_core\definitions\decorators\asset_decorator.py", line 744, in inner builder = DecoratorAssetsDefinitionBuilder.for_multi_asset(args=args, fn=fn) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myusername\Documents\my_project\.venv\Lib\site-packages\dagster\_core\definitions\decorators\decorator_assets_definition_builder.py", line 328, in for_multi_asset return DecoratorAssetsDefinitionBuilder.from_asset_outs_in_asset_centric_decorator( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\myusername\Documents\my_project\.venv\Lib\site-packages\dagster\_core\definitions\decorators\decorator_assets_definition_builder.py", line 461, in from_asset_outs_in_asset_centric_decorator internal_deps = {keys_by_output_name[name]: asset_deps[name] for name in asset_deps} ~~~~~~~~~~~~~~~~~~~^^^^^^ KeyError: 'sqlmesh__my-gcp-project_my_schema_example_model'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assets fail to load when GBQ project name contains a hyphen

1 participant