Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Prefect dbt 0.2.6 coroutine error #104

Closed
lucienfregosibodyguard opened this issue Dec 8, 2022 · 26 comments · Fixed by #112 or #122
Closed

Prefect dbt 0.2.6 coroutine error #104

lucienfregosibodyguard opened this issue Dec 8, 2022 · 26 comments · Fixed by #112 or #122

Comments

@lucienfregosibodyguard
Copy link
Contributor

Hi @ahuang11

Following this issue Sadly it's still doesn't work, got a new error

Encountered exception during execution:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/prefect/engine.py", line 1339, in orchestrate_task_run
    result = await task.fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/prefect_dbt/cli/commands.py", line 139, in trigger_dbt_cli_command
    yaml.dump(profile, f, default_flow_style=False)
  File "/usr/local/lib/python3.10/site-packages/yaml/__init__.py", line 253, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/usr/local/lib/python3.10/site-packages/yaml/__init__.py", line 241, in dump_all
    dumper.represent(data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/usr/local/lib/python3.10/site-packages/yaml/representer.py", line 317, in represent_object
    reduce = data.__reduce_ex__(2)
TypeError: cannot pickle 'coroutine' object

I guess it's related to the async function definition but don't know how to fix it

@ahuang11
Copy link
Contributor

ahuang11 commented Dec 8, 2022

Do you have this wrapped in a flow? Also are you working in notebook?

Here's something you can try in notebook / script.

from prefect import flow
from prefect_gcp import GcpCredentials
from prefect_dbt.cli import DbtCliProfile
from prefect_dbt.cli.configs import BigQueryTargetConfigs


@flow
def test_flow():
    credentials = GcpCredentials()

    target_configs = BigQueryTargetConfigs(
        credentials=credentials,
        schema="schema",
        project="project",
    )
    dbt_cli_profile = DbtCliProfile(
        name="jaffle_shop",
        target="dev",
        target_configs=target_configs,
    )
    profile = dbt_cli_profile.get_profile()
    return profile

test_flow()

@lucienfregosibodyguard
Copy link
Contributor Author

No the code is directly run within a kubernetes pod.

Locally it seems to work

@ahuang11
Copy link
Contributor

ahuang11 commented Dec 9, 2022

Can you try to see if this branch potentially fixes the issue? I made the base class method also sync compatible, but unsure if it'll help.

https://github.com/PrefectHQ/prefect-dbt/pull/105/files

@lucienfregosibodyguard
Copy link
Contributor Author

I have the same issue sadly :/

Finished in state Failed(message="Flow run encountered an exception. TypeError: cannot pickle 'coroutine' object\n", type=FAILED, result=TypeError("cannot pickle 'coroutine' object"))

@ahuang11
Copy link
Contributor

I suspect it's due to PrefectHQ/prefect-gcp#80 not yet released. Could you try pulling prefect-gcp main?

e.g. in requirements.txt prefect-gcp @ git+https://github.com/PrefectHQ/prefect-gcp.git@main

@lucienfregosibodyguard
Copy link
Contributor Author

Same issue with the prefect-gcp version 0.1.8+2.g28f72ba

@ahuang11
Copy link
Contributor

To clarify: "No the code is directly run within a kubernetes pod."

Is your code wrapped in a flow?

@lucienfregosibodyguard
Copy link
Contributor Author

Sure all the code is wrapped in a flow and triggered with prefect

@ahuang11
Copy link
Contributor

Thanks for confirming and I appreciate your help testing! I made another commit on https://github.com/PrefectHQ/prefect-dbt/pull/105/files

Can you help me test that again? If this doesn't work, I think we might have to make it sync again.

@lucienfregosibodyguard
Copy link
Contributor Author

@ahuang11 I'm so sorry It still doesn't work :( with same error

@ahuang11
Copy link
Contributor

Thanks for testing. Can you provide a minimal reproducible example that we can try on our end?

@lucienfregosibodyguard
Copy link
Contributor Author

hey @ahuang11
Actually I got this error even with the previous authentication method.

The 0.2.6 is broken for us because of the co routine error

It can be hard to reproduce the error because it happens only in a Kubernetes context (it works well locally)

  1. Package a docker image based on prefect 2.7.0-python3.10 with this version
    prefect-dbt = "0.2.6"
    dbt-bigquery = "1.3.0"
    prefect-gcp = "0.1.6"

  2. Add code to the docker image
    the code can be taken from the official prefect gcp example the error raises with any prefect_dbt.cli.commands import trigger_dbt_cli_command

  3. Create a storage & kubernetes block based on the previous docker image which will be used by the flow

  4. Start a flow in the prefect UI

If it's too hard for you to replicate this, we can plan a call or even let you use my mac remotely

@ahuang11 ahuang11 mentioned this issue Dec 30, 2022
5 tasks
@ahuang11
Copy link
Contributor

Thanks for that; can you try #111 to see if this fixes the issue? I dropped the async.

@lucienfregosibodyguard
Copy link
Contributor Author

@ahuang11 yes now it works perfectly with the last fix

@lucienfregosibodyguard
Copy link
Contributor Author

It it possible to merge and release a 0.2.8 package ? :)

@ahuang11
Copy link
Contributor

ahuang11 commented Jan 3, 2023

Yes I'll try to get the PR ready soon!

@ahuang11
Copy link
Contributor

@lucienfregosibodyguard by any chance, are you loading a DbtCliProfile like shown in #114?

@lucienfregosibodyguard
Copy link
Contributor Author

lucienfregosibodyguard commented Jan 16, 2023

Here is my DbtCliProfile Definition

    def _get_credentials(self) -> GcpCredentials:
        return GcpCredentials()

    def _get_target_configs(self) -> BigQueryTargetConfigs:
        return BigQueryTargetConfigs(
            schema=self.dataset_name, project=self.gcp_project, credentials=self._get_credentials()
        )

    def _get_dbt_cli_profile(self) -> DbtCliProfile:
        return DbtCliProfile(
            name=self.dbt_folder_name, target=self.environment, target_configs=self._get_target_configs()
        )

let me know if it's not the up to date version to load DbtCliProfile

@ahuang11
Copy link
Contributor

Okay so you don't use .save or .load?

@lucienfregosibodyguard
Copy link
Contributor Author

No I can try with save and load

@lucienfregosibodyguard
Copy link
Contributor Author

It seems better actually i don't have the coroutine error, it starts the DBT command and I got this

�[0m13:50:46  Encountered an error while reading profiles:
�[0m13:50:46    ERROR: Runtime Error
  Credentials in profile "dbt_models", target "" invalid: 'method' is a required property

Which is a "normal" error that should be solved in your PR

@lucienfregosibodyguard
Copy link
Contributor Author

Hi @ahuang11 could you release a new tag to easily test this and update my code ?

@ahuang11
Copy link
Contributor

ahuang11 commented Feb 7, 2023

Actually this isn't fixed yet. Will try to get a new release soon...

@lucienfregosibodyguard
Copy link
Contributor Author

@ahuang11 could we make a new tag with the last fix ?

@ahuang11
Copy link
Contributor

Done!

@lucienfregosibodyguard
Copy link
Contributor Author

Thaaaaaaaks it works like a charm awesome

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants