Repository: PrefectHQ/prefect

Issue:
Deployment default values are no longer usable after setting and registering them
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the Prefect documentation for this issue.
- [X] I checked that this issue is related to Prefect and not one of its dependencies.

### Bug summary

The deployment registration process will check if there exists a previous deployment and if so, load said deployment to prepolulate any values that were not provided.

This behavior is not optional, yet it should be. I created a deployment that is supposed to run in a process and provided a wrong path, the behavior I want is to not provide a path and use the default -- this bug stops me from doing so because it will always pre-load my new deployment with the old one, instead of overwritting it.

A possible fix would be to simply make this behaviour optional through a flag in the following code:
https://github.com/PrefectHQ/prefect/blob/b19c5e635631c50b7ebd02c27e4e838855f0f3b4/src/prefect/deployments.py#L576

### Reproduction

```python
# 1. Register a deployment with a path
Deployment.build_from_flow(
  flow,
  name=f"{deployment_name}-{infrastructure}",
  path="some/path"
).apply()

# 2. Re-register the same deployment without a path
Deployment.build_from_flow(
  flow,
  name=f"{deployment_name}-{infrastructure}",
).apply()

# 3. The last deployment with have path be "some/path"
```


### Error

NA

### Versions

```
Version:             2.4.0
API version:         0.8.0
Python version:      3.8.9
Git commit:          513639e8
Built:               Tue, Sep 13, 2022 2:15 PM
OS/Arch:             darwin/x86_64
Profile:             default
Server type:         hosted
```


### Additional context

_No response_


Discussion:
A toggle for the `load` behavior makes sense to me! Let's see what our product team thinks.

Resolving patch:
diff --git a/src/prefect/deployments.py b/src/prefect/deployments.py
--- a/src/prefect/deployments.py
+++ b/src/prefect/deployments.py
@@ -650,14 +650,12 @@ 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
@@ -665,6 +663,8 @@ async def build_from_flow(
                 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:
@@ -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)


Test patch:
diff --git a/tests/test_deployments.py b/tests/test_deployments.py
--- a/tests/test_deployments.py
+++ b/tests/test_deployments.py
@@ -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):