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

Pass existing environment variables to agentless flow runs #4917

Merged
merged 3 commits into from
Aug 31, 2021

Conversation

zanieb
Copy link
Contributor

@zanieb zanieb commented Aug 30, 2021

Summary

Includes the local environment in agentless flow runs by default. This was previously not available as I did not want to expose the entire local environment to flow runs--it seemed like a security risk.

Alternatively, we could allow opt-in for a list of environment variables or encourage users to pass thing via prefect local secrets.

Importance

Users frequently store environment variables that their flows needs on the machine their flow runs on

Checklist

This PR:

  • adds new tests (if appropriate)
  • adds a change file in the changes/ directory (if appropriate)
  • updates docstrings for any new functions or function arguments, including docs/outline.toml for API reference docs (if appropriate)

@zanieb zanieb requested a review from zangell44 as a code owner August 30, 2021 17:09
@zanieb
Copy link
Contributor Author

zanieb commented Aug 31, 2021

@TylerWanner @anticorrelator review me please

@TylerWanner
Copy link
Contributor

LGTM! Feels like a usability lift, though I wouldn't suggest anyone to inject env vars from execution environment into a flow run in production, if avoidable. It is good practice to make the execution environment as agnostic as possible, and it is a bad idea to throw some undefined sack of env vars around like this in production, but this can be very useful in development.

@TylerWanner
Copy link
Contributor

I see now this is actually True by default and has no interface for toggling. I would prefer it be False by default, but might be convinced otherwise. Would strongly prefer that this add a flag to toggle either way.

@TylerWanner
Copy link
Contributor

Sorry for waffling here. Given that agentless execution is a subprocess and not directly equivalent to running via agent, it does make sense to include the host env vars by default. In fact, this expectation should be clear enough that I do not think it needs a toggle. Anybody using --execute is effectively taking ownership of their execution environment (away from Prefect), and should expect it to work this way.

Copy link
Contributor

@anticorrelator anticorrelator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


# Should pass the correct flow run id to wait for
mocks.wait_for_flow_run_start_time.assert_called_once_with("flow-run-id")

# Merge the starting env and the env generated for a flow run
base_env = os.environ.copy() if include_local_env else {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always had an idiosyncratic preference for dict() instead of {} because of the visual similarity to set syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I may do that more in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants