-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Enhancement] Enable adapter.get_columns_in_relation()
macro to return columns during unit testing
#10139
Comments
FYI |
I'm not sure if this is the same underlying issue or not, but I just opened this issue that looks similar: |
Thanks for reaching out about this @DmytroSly ! Could you provide a simplified version of the models you are having trouble with? e.g., something like this:
select 1 as id
{%- set columns = adapter.get_columns_in_relation(ref('model_a')) -%}
{% for column in columns %}
{{ log("Column: " ~ column, info=true) }}
{% endfor %}
select 2 as guid |
I ran into the same problem when writing a unit test using the dbt.utils get_columns_in_relation function, hence why I'm adding to this issue, hope thats fine :) The model input
The dbt run is successful and the compiled code looks fine:
However when I run a dbt unit test with the same input as a csv fixture, the test fails with the following error message:
Looking at the compiled code it seems that the dbt unit test is not correctly passing the get_columns_in_relation function or the function is returning nothing:
Hope this helps, would be great if this was resolved or anyone has an idea how to fix this behaviour. |
That is very helpful @Elisabeth-Kury 🤩 Full details for a reproducible example, including unit test definition below.
|
I think this is another case where actually materializing the fixtures as database objects would work, because then each call to I expect that will be significantly slower in the general case, but it would allow the framework to support more-complex models — so while it shouldn't replace the default, it should be something that users can opt into. |
@dbeatty10, @jtcohen6, does it mean this issue will be fixed in dbt version 1.9? |
@DmytroSly We've ambitiously slated it as a potential candidate for v1.9, but it's not guaranteed for inclusion |
adapter.get_columns_in_relation()
macro to return columns during unit testing
Switching from a bug to a feature request because not being able to introspective queries on the given inputs to unit tests is a known limitation. |
Is this a new bug in dbt-core?
Current Behavior
The model I configured a unit test for, relies on the macro adapter.get_columns_in_relation() that I use for one of the models, referenced with the ref() macro. However, the macro adapter.get_columns_in_relation() returns an empty list for a relation during unit testing. This causes the SQL code to compile improperly and fail.
Expected Behavior
The macro adapter.get_columns_in_relation() should return a list of columns for a referenced relation during unit testing.
Steps To Reproduce
Create a SQL model that relies on the list of columns returned by the macro adapter.get_columns_in_relation(), then configure and run a unit test for this model
Relevant log output
No response
Environment
Which database adapter are you using with dbt?
snowflake
Additional Context
I hope it is possible to fix this, since dbt knows for sure the list of columns of all the referenced models. Apart from the input columns provided in the unit test config, dbt injects all other columns with NULL values into the resulting SQL for such a unit test. The input tables for a model, that I am trying to unit test, are really wide - 70-80 columns.
The text was updated successfully, but these errors were encountered: