Skip to content
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

trigger_dbt_cloud_job_run_and_wait_for_completion in prefect-dbt doesn't work as expected in 3.0.1 #15347

Closed
bjorhn opened this issue Sep 11, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bjorhn
Copy link
Contributor

bjorhn commented Sep 11, 2024

Bug summary

In prefect 3.0.1, trigger_dbt_cloud_job_run_and_wait_for_completion appears to exit immediately. This happens when executing it both from a sync or an async flow. We usually run it from a sync flow but decided to try with async to see if it'd work, or if perhaps we had to await trigger_dbt_cloud_job_run_and_wait_for_completion, which is an async subflow (marked as sync compatible, I believe). Awaiting it produced an error message.

I don't have any detailed logs at the moment but it should be easy to re-create.

In our case, the parent flow that is attempting to trigger and wait for the dbt cloud job run simply exits successfully (state = Completed), without trigger_dbt_cloud_job_run_and_wait_for_completion having created a subflow.

dbt_cloud_logs = trigger_dbt_cloud_job_run_and_wait_for_completion(
            dbt_cloud_credentials=dbt_cloud_credentials,
            job_id=DBT_JOB_IDS.get(env.value),
            trigger_job_run_options=trigger_job_run_options,
            max_wait_seconds=10800,  # 3 hours
            retry_filtered_models_attempts=0,
        )

logger.info(dbt_cloud_logs)

We have a temporary workaround in place but we're not entirely sure why it's necessary:

dbt_cloud_logs = asyncio.run(
            trigger_dbt_cloud_job_run_and_wait_for_completion(
                dbt_cloud_credentials=dbt_cloud_credentials,
                job_id=DBT_JOB_IDS.get(env.value),
                trigger_job_run_options=trigger_job_run_options,
                max_wait_seconds=10800,  # 3 hours
                retry_filtered_models_attempts=0,
            )
        )

logger.info(dbt_cloud_logs)

Version info (prefect version output)

Version:             3.0.1
API version:         0.8.4
Python version:      3.11.9
Git commit:          c6b2ffe1
Built:               Fri, Sep 6, 2024 10:05 AM
OS/Arch:             linux/x86_64
Profile:             default
Server type:         cloud
Pydantic version:    2.8.2
Integrations:
  prefect-dbt:       0.6.0
  prefect-snowflake: 0.28.0
  prefect-shell:     0.3.0
  prefect-azure:     0.4.0

Additional context

No response

@bjorhn bjorhn added the bug Something isn't working label Sep 11, 2024
@bjorhn bjorhn changed the title trigger_dbt_cloud_job_run_and_wait_for_completion in prefect-dbt doesn't work properly in 3.0.1 trigger_dbt_cloud_job_run_and_wait_for_completion in prefect-dbt doesn't work as expected in 3.0.1 Sep 11, 2024
@cicdw
Copy link
Member

cicdw commented Sep 12, 2024

Hi @bjorhn - sync/async handling was updated in 3.0 as we slowly move to a more explicit interface.

In this case, as you identified, trigger_dbt_cloud_job_run_and_wait_for_completion is an asynchronously defined flow and Prefect 3.0 removed support for calling asynchronous flow and task objects in synchronous contexts.

So you will need to await this flow for it to be executed properly.

@bjorhn
Copy link
Contributor Author

bjorhn commented Sep 12, 2024

Hey Chris - You're right. Running it in an async flow works fine, my dev just wasn't aware of some other changes related to the migration that had to be made as well (mostly related to block loading). I was mistaken about the dbt flow being sync_compatible, too. Probably shouldn't create issues when I don't have the code in front of me, got too excited about finishing the migration to 3.0

Thanks for the assistance.

@bjorhn bjorhn closed this as completed Sep 12, 2024
@cicdw
Copy link
Member

cicdw commented Sep 12, 2024

No worries, having it written up as an issue will probably help some other user when they search!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants