question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prefect User Config not working with Prefect cloud

See original GitHub issue

Description

A clear description of the bug Working with user config files locally works great, as described in this document

However, I’ve tried exporting a user config file (.toml) to prefect cloud (we’re running the Fargate agent). I do this by copying the file into docker storage using the files arg. I then set the environment variable PREFECT__USER_CONFIG_PATH to the path of this .toml file.

The flows get deployed successfully, the file gets copied over and the envar gets set. However, when the flow is executed on cloud, and we call prefect.config.SFK_USER we get the following error:

`DEBUG Task ‘execute_snowflake_query[0]’: Calling task.run() method…
2019-11-9 3:38pm prefect.CloudTaskRunner

As an alternative way of deploying the config, rather than setting PREFECT__USER_CONFIG_PATH, I tried parsing the .toml file during the deployment and prefixing every envar with PREFECT__ and just adding these envars to the env_vars arg in docker storage. This produced the same error (above).

Expected Behavior

What did you expect to happen instead? I would expect the value of prefect.config.SFK_USER to get returned, just as it does when I run this locally.

Reproduction

A minimal example that exhibits the behavior.

  1. create a file called uat.toml. Inside of this file put SFK_USER = PREFECT_READ_ONLY
  2. in your flow code, call prefect.config.SFK_USER within one of your tasks

Deploy Flow 3. when deploying your flow to docker storage, in the files arg, use the source and destination of this file to copy the file into the docker container 4. in the env_vars arg, set PREFECT__USER_CONFIG_PATH to the destination file path of uat.toml

Run the Flow 5. From prefect cloud trigger the newly deployed flow

Environment

Any additional information about your environment We’re running the Fargate Agent

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mhmcdonaldcommented, Nov 25, 2019

Thanks, @cicdw. This makes sense. We will definitely use the prefect.* pattern going forward.

I’ll go ahead and close this issue.

0reactions
cicdwcommented, Nov 25, 2019

Hi @mhmcdonald ! I’ve been lurking and I think I know what’s going on. It’s a little complicated, but ultimately boils down to how Flows are serialized and stored (using cloudpickle).

Whenever you use the

from prefect import task, Flow, config

@task
def test():
    return config.MY_VAR

pattern, cloudpickle freezes the config object as-is. However, whenever you use

import prefect
from prefect import task, Flow

@task
def test():
    return prefect.config.MY_VAR

cloudpickle recognizes config as something it can access as a module attribute, and therefore at runtime it dynamically loads the configuration object (as you were expecting). In general we recommend the prefect.* pattern for both config and context for this reason.

You can see this in action if you call cloudpickle.dumps(...) on each of the above tasks – you’ll notice that one of them produces a large output with your entire config file, whereas the other one is very minimal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting - Prefect 2 - Coordinating the world's dataflows
Use the prefect config view CLI command to make sure your execution environment is correctly configured to access Prefect Cloud.
Read more >
Configuration | Prefect Docs
Prefect's settings are stored in a configuration file called config.toml . In general, you should not edit this file directly to modify Prefect's...
Read more >
Troubleshooting Prefect Server issues - list of resources you ...
This documentation shows how to deploy Server to a single machine. It's important to: Switch your backend to Server (default is Cloud): ...
Read more >
Prefect 2.0 User Configurations to Configuration Profiles ...
Troubleshooting. For prefect cloud If you don't specify the PREFECT_API_URL and the PREFECT_API_KEY manually within your active profile then ...
Read more >
Configuration Options - Prefect Docs
If you are running Prefect Server, you can update the server.host and server.port config settings to point to a new API endpoint.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found