-
Notifications
You must be signed in to change notification settings - Fork 180
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
[Bug] dbt_vars raised "This can happen when calling a macro that does not exist" #1060
Comments
Hello @rightx2! 👋 I'm here to help you with any bugs, questions, or contributions. Let me know how I can assist you! The issue you're encountering with the To address this, you can try using import json
from cosmos.config import ProjectConfig, ProfileConfig, RenderConfig, ExecutionConfig, LoadMode, ExecutionMode
from cosmos.task_group import DbtTaskGroup
project_config = ProjectConfig(
dbt_project_path="/opt/airflow/dbt/data-dbt",
project_name="data_dbt",
partial_parse=True,
dbt_vars=json.dumps({
"start_dt": '{{ data_interval_end }}',
}),
)
profile_config = ProfileConfig(
profile_name="data_dbt",
target_name="dev",
profiles_yml_filepath=Path("/opt/airflow/dbt/data-dbt", "profiles", "profiles.yml"),
)
render_config = RenderConfig(
load_method=LoadMode.DBT_LS,
emit_datasets=False,
test_behavior=TestBehavior.AFTER_EACH,
select=[
"models/my_model.sql",
],
)
execution_config = ExecutionConfig(
execution_mode=ExecutionMode.LOCAL,
)
operator_args = {
"install_deps": True,
}
dbt_op = DbtTaskGroup(
group_id="dbt_group",
project_config=project_config,
profile_config=profile_config,
render_config=render_config,
execution_config=execution_config,
operator_args=operator_args,
) This change should help ensure that the |
docs seems to say it worked... looks strange |
Really important question: Does this error occur in task execution or in DAG parsing/rendering? I.e. is the error message on the homepage of Airflow and causes the DAG to not even load at all? |
I'm going ahead with the assumption that this occurs in DAG rendering and not task execution. The reason why is because I'm pretty confident I know what the problem is because I knew back in January that this problem would one day bite someone in the butt, and I have advocated for making changes to this precisely because of the issue you just ran into. The problem:Right now dbt vars + env are strongly coupled across both rendering and execution, but they should be looser because of precisely what you are attempting to do. In Airflow, During rendering of the DAG, Jinja2 is not used at all. This means that the string literal The reason it doesn't raise an error when you do How you can fix today:You should look into using How Cosmos can fix:As per my comment in January, vars and the env should be allowed to be decoupled. Errors should not be raised when a user attempts to set |
your assumption is right: it happend in rendering time. And the reason of the problem I was thinking about matches exactly with what you mentioned.. I think I'd take another render method. Thanks |
One more note I didn't mention is that your use case is not atypical. I think injecting DagRun variables like the data interval end should be supported. It's very natural to want to do that. And it clearly is not supported right now. I think we should make this a more explicitly supported pattern. So keep doing what you're doing and don't be discouraged! |
of course i will : ) |
Astronomer Cosmos Version
Other Astronomer Cosmos version (please specify below)
If "Other Astronomer Cosmos version" selected, which one?
1.4.3
dbt-core version
1.7.16
Versions of dbt adapters
dbt-impala==1.4.3 (but i don't think this issue related with adapter)
LoadMode
DBT_LS
ExecutionMode
LOCAL
InvocationMode
None
airflow version
2.9.1
Operating System
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)"
If a you think it's an UI issue, what browsers are you seeing the problem on?
No response
Deployment
Official Apache Airflow Helm Chart
Deployment details
No response
What happened?
dbt_vars can raise "This can happen when calling a macro that does not exist"
Relevant log output
How to reproduce
I need to pass variable,
start_dt
, to dbt_models withdata_interval_end
macro of airflow. Below is my configuration for cosmos dag and it worked like a charm.However, when I tried to call function of macro like below, it raised error:
dbt model:
error:
I think this is due to how
yaml.dump
works in here (I think usingjson.dumps
will work...).Is there any way I can pass variable to dbt_models with macro function?
Anything else :)?
written in above
Are you willing to submit PR?
Contact Details
rightx2@gmail.com
The text was updated successfully, but these errors were encountered: