fal-ai / dbt-fal

do more with dbt. dbt-fal helps you run Python alongside dbt, so you can send Slack alerts, detect anomalies and build machine learning models.
https://fal.ai/dbt-fal
Apache License 2.0
853 stars 72 forks source link

Post-hooks do not work for Python models with dbt-fal, postgres adapter #913

Open tarnpreetb123 opened 6 months ago

tarnpreetb123 commented 6 months ago
**Describe the bug**
-- models/input/model_a.sql
select 1 as pk
# models/base/model_b.py
def model(dbt, session):
    df = dbt.ref("model_a")
    return df
---dbt_project.yml
models:
    input:
      +materialized: table
      schema: input
    base:
      +materialized: table
      schema: base
      +post-hook:
           sql: " {{ alter_pk() }} "
           transaction: false
---alter_pk.sql
{% macro alter_pk() %}
    ALTER TABLE {{this}}
    ADD PRIMARY KEY(pk)
{% endmacro %}

Using a python model with the postgres adapter, the post_hook is ignored. Calling it from the model, or the dbt_project.yml results in the same behavior of it being ignored.

Your environment

Using dbt-postgres: 1.5.5
and dbt-fal: 1.5.9

- OS: Windows 10
- Python: 3.10.7
- dbt:1.5.5
- fal: 1.5.9

Expected behavior I expect the post-hook to run the sql command like it would for a sql model. Actual behavior

Additional context https://github.com/dbt-labs/dbt-core/issues/9310