Skip to content

Commit

Permalink
avoid Path interpreting . in deployment names as the beginning of…
Browse files Browse the repository at this point in the history
… a file extension (#16553)
  • Loading branch information
zzstoatzz authored Dec 31, 2024
1 parent 94814ed commit 323a8f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/prefect/deployments/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def fast_flow():
ConfigDict,
Field,
PrivateAttr,
field_validator,
model_validator,
)
from rich.console import Console
Expand Down Expand Up @@ -220,6 +221,13 @@ class RunnerDeployment(BaseModel):
def entrypoint_type(self) -> EntrypointType:
return self._entrypoint_type

@field_validator("name", mode="before")
@classmethod
def validate_name(cls, value: str) -> str:
if value.endswith(".py"):
return Path(value).stem
return value

@model_validator(mode="after")
def validate_automation_names(self):
"""Ensure that each trigger has a name for its automation if none is provided."""
Expand Down Expand Up @@ -508,7 +516,7 @@ def from_flow(
concurrency_options = None

deployment = cls(
name=Path(name).stem,
name=name,
flow_name=flow.name,
schedules=constructed_schedules,
concurrency_limit=concurrency_limit,
Expand Down
10 changes: 10 additions & 0 deletions tests/runner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,16 @@ async def test_init_runner_deployment_with_invalid_schedules(self):
],
)

async def test_deployment_name_with_dots(self):
# regression test for https://github.com/PrefectHQ/prefect/issues/16551
deployment = RunnerDeployment.from_flow(dummy_flow_1, name="..test-deployment")
assert deployment.name == "..test-deployment"

deployment2 = RunnerDeployment.from_flow(
dummy_flow_1, name="flow-from-my.python.module"
)
assert deployment2.name == "flow-from-my.python.module"


class TestServer:
async def test_healthcheck_fails_as_expected(self):
Expand Down

0 comments on commit 323a8f8

Please sign in to comment.