Skip to content

Commit

Permalink
Add toggle to load of existing deployment values (#7218)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte committed Oct 19, 2022
1 parent b3e5b7d commit 7aea3e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/prefect/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,21 +650,21 @@ async def build_from_flow(
output: str = None,
skip_upload: bool = False,
apply: bool = False,
load_existing: bool = True,
**kwargs,
) -> "Deployment":
"""
Configure a deployment for a given flow.
Note that this method loads any settings that may already be configured for the named deployment
server-side (e.g., schedules, default parameter values, etc.).
Args:
flow: A flow function to deploy
name: A name for the deployment
output (optional): if provided, the full deployment specification will be written as a YAML
file in the location specified by `output`
skip_upload: if True, deployment files are not automatically uploaded to remote storage
apply: if True, the deployment is automatically registered with the API
load_existing: if True, load any settings that may already be configured for the named deployment
server-side (e.g., schedules, default parameter values, etc.)
**kwargs: other keyword arguments to pass to the constructor for the `Deployment` class
"""
if not name:
Expand All @@ -691,7 +691,8 @@ async def build_from_flow(
entry_path = Path(flow_file).absolute().relative_to(Path(".").absolute())
deployment.entrypoint = f"{entry_path}:{flow.fn.__name__}"

await deployment.load()
if load_existing:
await deployment.load()

# set a few attributes for this flow object
deployment.parameter_openapi_schema = parameter_schema(flow)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,32 @@ async def test_build_from_flow_sets_provided_attrs(self, flow_function):
assert d.tags == ["A", "B"]
assert d.version == "12"

async def test_build_from_flow_doesnt_load_existing(self, flow_function):
d = await Deployment.build_from_flow(
flow_function,
name="foo",
tags=["A", "B"],
description="foobar",
version="12",
)
assert d.flow_name == flow_function.name
assert d.name == "foo"
assert d.description == "foobar"
assert d.tags == ["A", "B"]
assert d.version == "12"

d = await Deployment.build_from_flow(
flow_function,
name="foo",
version="12",
load_existing=False,
)
assert d.flow_name == flow_function.name
assert d.name == "foo"
assert d.description != "foobar"
assert d.tags != ["A", "B"]
assert d.version == "12"


class TestYAML:
def test_deployment_yaml_roundtrip(self, tmp_path):
Expand Down

0 comments on commit 7aea3e8

Please sign in to comment.