fix: ref() and source() in Python models #666
Merged
yotahk merged 4 commits intoaws-samples:mainfrom Mar 12, 2026
Merged
Conversation
…unctions
The previous implementation constructed table references manually. When calling
`source("my_source_aliase", "my_table")` it would literally pass those string into
`spark.table` resulting in a call `spark.table("my_source_aliase"."my_table")`.
This fix will resolve this issue with reutilization of
```py
def ref(*args, **kwargs):
refs = {"my_ref_table": "my_schema.my_ref_table"}
key = '.'.join(args)
version = kwargs.get("v") or kwargs.get("version")
if version:
key += f".v{version}"
dbt_load_df_function = kwargs.get("dbt_load_df_function")
return dbt_load_df_function(refs[key])
def source(*args, dbt_load_df_function):
sources = {"my_source_aliase.my_source_table": "my_source_schema.my_source_table"}
key = '.'.join(args)
return dbt_load_df_function(sources[key])
```
**NOTE:** that instead of having `my_source_aliase` it instead points to
`my_source_schema`, which would solve the issue of an incorrect pointer with
`spark.table`, outputting `spark.table("my_source_schema"."my_source_table")`
This took me ages to figure out, was so confused on why there was source
declaration.
Contributor
Author
|
I believe this also fixes the issue: #635 |
Collaborator
|
Thanks for the fix. I believe delegating to dbt-core's resolved ref/source functions (as defined in py_script_postfix) is the right approach. One small ask: could you add an entry to CHANGELOG.md for this change & complete the PR checklist? |
update: CHANGELOG.md
Contributor
Author
Hey @yotahk, You'll find the updates, thanks to Claude was able to understand how in the god's name to create test. |
yotahk
approved these changes
Mar 12, 2026
Collaborator
|
Merged, thank you for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: ref() and source() in Python models to use dbt-core's resolved functions
The previous implementation constructed table references manually. When calling
source("my_source_aliase", "my_table")it would literally pass those string intospark.tableresulting in a callspark.table("my_source_aliase"."my_table").This fix will resolve this issue with reutilization of
NOTE: that instead of having
my_source_aliaseit points tomy_source_schema, which would solve the issue of an incorrect pointer withspark.table, outputtingspark.table("my_source_schema"."my_source_table")This took me ages to figure out, was so confused on why there was source declaration.
resolves #
Description
Checklist
CHANGELOG.mdand added information about my change to the "dbt-glue next" section.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.