internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: PrefectHQ/prefect

Issue:
Deprecate `FlowRunCreate.deployment_id`
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar request and didn't find it.
- [X] I searched the Prefect documentation for this feature.

### Prefect Version

2.x

### Describe the current behavior

`FlowRunCreate` accepts a `deployment_id` but the flow run is not properly linked to the deployment when `api/flow_runs` is used. For example, the flow run will not be given an associated work queue or pool so it will not be run by a worker. Instead, `DeploymentFlowRunCreate` should be used which is at `api/deployments/create_flow_run`.

### Describe the proposed behavior

We should deprecate and eventually remove this field.

### Example Use

Users will be less likely to hit the wrong endpoint when creating flow runs manually.

### Additional context

User experience at https://prefect-community.slack.com/archives/CL09KU1K7/p1683215369752279


Discussion:
Can I be assigned to this issue, @madkinsz ?
I'm new to open source and learning to contribute.
Thank you, @madkinsz, for assigning me this!
I'm new to Perfect! So, I need more detail on what needs to be done here.
And please let me know guides/resources & docs I need to go through to understand this.

Thank you in advance!
@ksharma20 here's an example deprecated field https://github.com/PrefectHQ/prefect/blob/6f552f3efe9475069540218306b52722a1a66669/src/prefect/server/schemas/actions.py#L564-L568

We'll want to add these deprecation marks to `FlowRunCreate.deployment_id`

When you build the API reference documentation `prefect dev build-docs && mkdocs serve` you should be able to see the field is deprecated.
Picked this up as it's been 2 moths since it's been assigned.

Resolving patch:
diff --git a/src/prefect/server/schemas/actions.py b/src/prefect/server/schemas/actions.py
--- a/src/prefect/server/schemas/actions.py
+++ b/src/prefect/server/schemas/actions.py
@@ -339,7 +339,6 @@ class FlowRunCreate(ActionBaseModel):
 
     name: str = FieldFrom(schemas.core.FlowRun)
     flow_id: UUID = FieldFrom(schemas.core.FlowRun)
-    deployment_id: Optional[UUID] = FieldFrom(schemas.core.FlowRun)
     flow_version: Optional[str] = FieldFrom(schemas.core.FlowRun)
     parameters: dict = FieldFrom(schemas.core.FlowRun)
     context: dict = FieldFrom(schemas.core.FlowRun)
@@ -349,6 +348,17 @@ class FlowRunCreate(ActionBaseModel):
     tags: List[str] = FieldFrom(schemas.core.FlowRun)
     idempotency_key: Optional[str] = FieldFrom(schemas.core.FlowRun)
 
+    # DEPRECATED
+
+    deployment_id: Optional[UUID] = Field(
+        None,
+        description=(
+            "DEPRECATED: The id of the deployment associated with this flow run, if"
+            " available."
+        ),
+        deprecated=True,
+    )
+
     class Config(ActionBaseModel.Config):
         json_dumps = orjson_dumps_extra_compatible
 


Test patch:
Repository: PrefectHQ/prefect

Issue:
Email notifications example form input needs adjusted
### 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


Here's the default example in a Prefect server UI.
<img width="1185" alt="Screenshot 2023-09-07 at 1 51 05 PM" src="https://github.com/PrefectHQ/prefect/assets/7703961/270dcce8-c9f8-484f-aeab-11dfebdabb92">

But this doesn't work. 
<img width="1187" alt="Screenshot 2023-09-07 at 1 51 24 PM" src="https://github.com/PrefectHQ/prefect/assets/7703961/d4e38e4f-9aa3-4c04-8615-3c5cf2144e50">

Quotes are required around the address.


### Reproduction

```python3
see above
```


### Error

_No response_

### Versions

```Text
Version:             2.12.1
API version:         0.8.4
Python version:      3.10.8
Git commit:          f5eed67c
Built:               Fri, Sep 1, 2023 
4:01 PM
OS/Arch:             darwin/arm64
Profile:             local
Server type:         ephemeral
Server:
  Database:          sqlite
  SQLite version:    3.40.0
```


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/blocks/notifications.py b/src/prefect/blocks/notifications.py
--- a/src/prefect/blocks/notifications.py
+++ b/src/prefect/blocks/notifications.py
@@ -749,7 +749,7 @@ class SendgridEmail(AbstractAppriseNotificationBlock):
         default=...,
         title="Recipient emails",
         description="Email ids of all recipients.",
-        example="recipient1@gmail.com",
+        example='"recipient1@gmail.com"',
     )
 
     def block_initialization(self) -> None:


Test patch:
Repository: PrefectHQ/prefect

Issue:
Allow customization of worker bind server addr
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar request and didn't find it.
- [X] I searched the Prefect documentation for this feature.

### Prefect Version

2.x

### Describe the current behavior

When we deploy a worker on Kubernetes, it is possible to activate [livenessProbe](https://github.com/PrefectHQ/prefect-helm/blob/main/charts/prefect-worker/values.yaml#L116-L128), unfortunately, [the server responsible for listening](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/workers/server.py#L42) to requests on the `/health` endpoint only listens to requests coming from `IPV4` addresses because of the hardcoded bind to `0.0.0.0`.

This is problematic in the case of a deployment on an `IPV6` only EKS cluster because we have no way of modifying this default behavior to also allow listening on `IPV6` via customization of this value, therefore the `livenessProbe` fail.

### Describe the proposed behavior

Allow to modify the bind address of the worker's health server with an environment variable named for example `PREFECT_WORKER_SERVER_HOST` as is the case with [PREFECT_SERVER_API_HOST](https://docs.prefect.io/2.14.3/api-ref/prefect/settings/?h=prefect_worker_#prefect.settings.PREFECT_SERVER_API_HOST) or [PREFECT_RUNNER_SERVER_HOST](https://docs.prefect.io/2.14.3/api-ref/prefect/settings/?h=prefect_worker_#prefect.settings.PREFECT_RUNNER_SERVER_HOST).

### Example Use

_No response_

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/settings.py b/src/prefect/settings.py
--- a/src/prefect/settings.py
+++ b/src/prefect/settings.py
@@ -1384,6 +1384,16 @@ def default_cloud_ui_url(settings, value):
 Can be used to compensate for infrastructure start up time for a worker.
 """
 
+PREFECT_WORKER_WEBSERVER_HOST = Setting(str, default="0.0.0.0")
+"""
+The host address the worker's webserver should bind to.
+"""
+
+PREFECT_WORKER_WEBSERVER_PORT = Setting(int, default=8080)
+"""
+The port the worker's webserver should bind to.
+"""
+
 PREFECT_EXPERIMENTAL_ENABLE_ARTIFACTS = Setting(bool, default=True)
 """
 Whether or not to enable experimental Prefect artifacts.
diff --git a/src/prefect/workers/server.py b/src/prefect/workers/server.py
--- a/src/prefect/workers/server.py
+++ b/src/prefect/workers/server.py
@@ -4,6 +4,10 @@
 from prefect._vendor.fastapi import APIRouter, FastAPI, status
 from prefect._vendor.fastapi.responses import JSONResponse
 
+from prefect.settings import (
+    PREFECT_WORKER_WEBSERVER_HOST,
+    PREFECT_WORKER_WEBSERVER_PORT,
+)
 from prefect.workers.base import BaseWorker
 from prefect.workers.process import ProcessWorker
 
@@ -39,4 +43,9 @@ def perform_health_check():
 
     webserver.include_router(router)
 
-    uvicorn.run(webserver, host="0.0.0.0", port=8080, log_level=log_level)
+    uvicorn.run(
+        webserver,
+        host=PREFECT_WORKER_WEBSERVER_HOST.value(),
+        port=PREFECT_WORKER_WEBSERVER_PORT.value(),
+        log_level=log_level,
+    )


Test patch:
Repository: PrefectHQ/prefect

Issue:
Add `concurrency` to `prefect-client` package
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar request and didn't find it.
- [X] I searched the Prefect documentation for this feature.

### Prefect Version

2.x

### Describe the current behavior

Currently, the `concurrency` submodule is removed during the `prefect-client` packaging process so (when using only prefect-client) imports like `from prefect.concurrency.sync import rate_limit` do not work when using the `prefect-client` package.

### Describe the proposed behavior

If possible, the concurrency submodule should be included in the `prefect-client` package.

### Example Use

`from prefect.concurrency.sync import rate_limit` when only prefect-client is installed.

### Additional context

_No response_


Discussion:
Hi @majikman111, thanks for the issue! @urimandujano might have thoughts on that

Resolving patch:
diff --git a/client/client_flow.py b/client/client_flow.py
--- a/client/client_flow.py
+++ b/client/client_flow.py
@@ -1,4 +1,5 @@
 from prefect import flow, task
+from prefect.concurrency import asyncio, common, events, services, sync  # noqa: F401
 
 
 def skip_remote_run():


Test patch:
Repository: PrefectHQ/prefect

Issue:
client read_logs has incorrect return type 
### 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

client `read_logs` incorrectly returns `None` and fails type checking in pyright/vscode

### Reproduction

```python3
page_logs = await client.read_logs(
                log_filter=LogFilter(flow_run_id={"any_": [flow_run.id]}),
            )
            for log in page_logs:
                ...
```


### Error

pyright errors with
```
error: "None" is not iterable (reportGeneralTypeIssues)
```


### Versions

```Text
2.14.9
```


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/client/orchestration.py b/src/prefect/client/orchestration.py
--- a/src/prefect/client/orchestration.py
+++ b/src/prefect/client/orchestration.py
@@ -2181,7 +2181,7 @@ async def read_logs(
         limit: int = None,
         offset: int = None,
         sort: LogSort = LogSort.TIMESTAMP_ASC,
-    ) -> None:
+    ) -> List[Log]:
         """
         Read flow and task run logs.
         """


Test patch:
Repository: PrefectHQ/prefect

Issue:
Document RunInput's send/receive basics in the `run_input` module.



Discussion:

Resolving patch:
diff --git a/src/prefect/input/run_input.py b/src/prefect/input/run_input.py
--- a/src/prefect/input/run_input.py
+++ b/src/prefect/input/run_input.py
@@ -1,3 +1,64 @@
+"""
+This module contains functions that allow sending type-checked `RunInput` data
+to flows at runtime. Flows can send back responses, establishing two-way
+channels with senders. These functions are particularly useful for systems that
+require ongoing data transfer or need to react to input quickly.
+real-time interaction and efficient data handling. It's designed to facilitate
+dynamic communication within distributed or microservices-oriented systems,
+making it ideal for scenarios requiring continuous data synchronization and
+processing. It's particularly useful for systems that require ongoing data
+input and output.
+
+The following is an example of two flows. One sends a random number to the
+other and waits for a response. The other receives the number, squares it, and
+sends the result back. The sender flow then prints the result.
+
+Sender flow:
+
+```python
+import random
+from uuid import UUID
+from prefect import flow, get_run_logger
+from prefect.input import RunInput
+
+class NumberData(RunInput):
+    number: int
+
+
+@flow
+async def sender_flow(receiver_flow_run_id: UUID):
+    logger = get_run_logger()
+
+    the_number = random.randint(1, 100)
+
+    await NumberData(number=the_number).send_to(receiver_flow_run_id)
+
+    receiver = NumberData.receive(flow_run_id=receiver_flow_run_id)
+    squared = await receiver.next()
+
+    logger.info(f"{the_number} squared is {squared.number}")
+```
+
+Receiver flow:
+```python
+import random
+from uuid import UUID
+from prefect import flow, get_run_logger
+from prefect.input import RunInput
+
+class NumberData(RunInput):
+    number: int
+
+
+@flow
+async def receiver_flow():
+    async for data in NumberData.receive():
+        squared = data.number ** 2
+        data.respond(NumberData(number=squared))
+```
+"""
+
+
 from typing import (
     TYPE_CHECKING,
     Any,


Test patch:
Repository: PrefectHQ/prefect

Issue:
no import statement for wait_for_flow_run
### First check

- [X] I added a descriptive title to this issue.
- [X] I used GitHub search to find a similar request and didn't find it 😇

### Describe the issue

There is no import statement for wait_for_flow_run so typing this code into pycharm shows wait_for_flow_run as an error.  Searching the internets, the import statement used to be

_from prefect.tasks.prefect import wait_for_flow_run_

yeah, that doesn't work anymore.

### Describe the proposed change

put the correct import statement in the docs which is 

_from prefect.flow_runs import wait_for_flow_run_



Discussion:

Resolving patch:
diff --git a/src/prefect/flow_runs.py b/src/prefect/flow_runs.py
--- a/src/prefect/flow_runs.py
+++ b/src/prefect/flow_runs.py
@@ -38,6 +38,7 @@ async def wait_for_flow_run(
             import asyncio
 
             from prefect import get_client
+            from prefect.flow_runs import wait_for_flow_run
 
             async def main():
                 async with get_client() as client:
@@ -55,6 +56,7 @@ async def main():
             import asyncio
 
             from prefect import get_client
+            from prefect.flow_runs import wait_for_flow_run
 
             async def main(num_runs: int):
                 async with get_client() as client:


Test patch:
Repository: PrefectHQ/prefect

Issue:
Send retry logs to the API
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar request and didn't find it.
- [X] I searched the Prefect documentation for this feature.

### Prefect Version

2.x

### Describe the current behavior

Currently with retries set on a task, if a failure occurs in the task there is an inconsistency with the information logged locally and in the prefect server. Locally, you get a `ERROR` log for the error that was raised and a `INFO` [log](https://github.com/PrefectHQ/prefect/blob/main/src/prefect/engine.py#L1794-L1801) saying the task will be retried. However that `INFO` log is explicitly set to not be sent to the API. 

### Describe the proposed behavior

I propose that sending the INFO log about retrying a task to the API provides useful observability into flow execution. 

### Example Use

End user's looking at the logs in the server gain insight into when a retry occurs without having to look for the logs in the local compute environment. 

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/engine.py b/src/prefect/engine.py
--- a/src/prefect/engine.py
+++ b/src/prefect/engine.py
@@ -958,7 +958,6 @@ async def orchestrate_flow_run(
                     f"Received non-final state {state.name!r} when proposing final"
                     f" state {terminal_state.name!r} and will attempt to run again..."
                 ),
-                extra={"send_to_api": False},
             )
             # Attempt to enter a running state again
             state = await propose_state(client, Running(), flow_run_id=flow_run.id)
@@ -2218,7 +2217,6 @@ async def tick():
                         f" state {terminal_state.name!r} and will attempt to run"
                         " again..."
                     ),
-                    extra={"send_to_api": False},
                 )
                 # Attempt to enter a running state again
                 state = await propose_state(client, Running(), task_run_id=task_run.id)


Test patch:
Repository: PrefectHQ/prefect

Issue:
Create endpoint to create/refresh CSRF Tokens



Discussion:

Resolving patch:
diff --git a/src/prefect/server/api/__init__.py b/src/prefect/server/api/__init__.py
--- a/src/prefect/server/api/__init__.py
+++ b/src/prefect/server/api/__init__.py
@@ -8,6 +8,7 @@
     collections,
     concurrency_limits,
     concurrency_limits_v2,
+    csrf_token,
     dependencies,
     deployments,
     flow_run_notification_policies,
diff --git a/src/prefect/server/api/csrf_token.py b/src/prefect/server/api/csrf_token.py
new file mode 100644
--- /dev/null
+++ b/src/prefect/server/api/csrf_token.py
@@ -0,0 +1,23 @@
+from prefect._vendor.fastapi import Depends, Query
+
+from prefect.logging import get_logger
+from prefect.server import models, schemas
+from prefect.server.database.dependencies import provide_database_interface
+from prefect.server.database.interface import PrefectDBInterface
+from prefect.server.utilities.server import PrefectRouter
+
+logger = get_logger("server.api")
+
+router = PrefectRouter(prefix="/csrf-token")
+
+
+@router.get("")
+async def create_csrf_token(
+    db: PrefectDBInterface = Depends(provide_database_interface),
+    client: str = Query(..., description="The client to create a CSRF token for"),
+) -> schemas.core.CsrfToken:
+    """Create or update a CSRF token for a client"""
+    async with db.session_context(begin_transaction=True) as session:
+        return await models.csrf_token.create_or_update_csrf_token(
+            session=session, client=client
+        )
diff --git a/src/prefect/server/api/server.py b/src/prefect/server/api/server.py
--- a/src/prefect/server/api/server.py
+++ b/src/prefect/server/api/server.py
@@ -83,6 +83,7 @@
     api.block_capabilities.router,
     api.collections.router,
     api.variables.router,
+    api.csrf_token.router,
     api.ui.flow_runs.router,
     api.ui.schemas.router,
     api.ui.task_runs.router,


Test patch:
diff --git a/tests/server/api/test_csrf_token.py b/tests/server/api/test_csrf_token.py
new file mode 100644
--- /dev/null
+++ b/tests/server/api/test_csrf_token.py
@@ -0,0 +1,33 @@
+from httpx import AsyncClient
+from sqlalchemy.ext.asyncio import AsyncSession
+
+from prefect.server import models, schemas
+
+
+async def test_can_get_csrf_token(client: AsyncClient, session: AsyncSession):
+    response = await client.get("/csrf-token?client=client123")
+    assert response.status_code == 200
+
+    token = schemas.core.CsrfToken(**response.json())
+    db_token = await models.csrf_token.read_token_for_client(
+        session=session, client="client123"
+    )
+
+    assert token.client == "client123"
+    assert token.token == db_token.token
+
+
+async def test_client_param_required(client: AsyncClient):
+    response = await client.get("/csrf-token")
+    assert response.status_code == 422
+    assert response.json() == {
+        "exception_detail": [
+            {
+                "loc": ["query", "client"],
+                "msg": "field required",
+                "type": "value_error.missing",
+            }
+        ],
+        "exception_message": "Invalid request received.",
+        "request_body": None,
+    }
Repository: PrefectHQ/prefect

Issue:
Support CSRF token handling in the UI



Discussion:

Resolving patch:
diff --git a/src/prefect/server/api/middleware.py b/src/prefect/server/api/middleware.py
--- a/src/prefect/server/api/middleware.py
+++ b/src/prefect/server/api/middleware.py
@@ -67,6 +67,7 @@ async def dispatch(
                     return JSONResponse(
                         {"detail": "Invalid CSRF token or client identifier."},
                         status_code=status.HTTP_403_FORBIDDEN,
+                        headers={"Access-Control-Allow-Origin": "*"},
                     )
 
         return await call_next(request)


Test patch:
Repository: PrefectHQ/prefect

Issue:
Docs for run_deployment incorectly specify that flow/deployment name must be slugified
### First check

- [X] I added a descriptive title to this issue.
- [X] I used GitHub search to find a similar request and didn't find it 😇

### Describe the issue

https://docs.prefect.io/2.11.3/api-ref/prefect/deployments/deployments/?h=run_deplo#prefect.deployments.deployments.run_deployment

The current docs say to provide a name in the form `<slugified-flow-name>/<slugified-deployment-name>`, but passing the function slugified names results in a 404 when `run_deployment` calls the Prefect cloud API to find the deployment. Passing the names specified by `flow_name` and `name` in the deployment file works as expected.

### Describe the proposed change

Instead of `<slugified-flow-name>/<slugified-deployment-name>`, provide an example with the correct format:
`'Flow Name/Deployment Name'`.

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/deployments/deployments.py b/src/prefect/deployments/deployments.py
--- a/src/prefect/deployments/deployments.py
+++ b/src/prefect/deployments/deployments.py
@@ -103,7 +103,7 @@ async def run_deployment(
 
     Args:
         name: The deployment id or deployment name in the form:
-            `<slugified-flow-name>/<slugified-deployment-name>`
+            `"flow name/deployment name"`
         parameters: Parameter overrides for this flow run. Merged with the deployment
             defaults.
         scheduled_time: The time to schedule the flow run for, defaults to scheduling


Test patch:
Repository: PrefectHQ/prefect

Issue:
Duplicate message in CLI on `prefect cloud login`
### 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

Duplicated output if try to authenticate from CLI.

```
It looks like you're already authenticated on this profile.
It looks like you're already authenticated on this profile.
```

<img width="600" alt="Screenshot 2024-04-11 at 8 59 25 AM" src="https://github.com/PrefectHQ/prefect/assets/7703961/10abd690-074a-4889-83c4-45de0edefaff">


### Reproduction

```python3
`prefect cloud login` from an already authenticated CLI
```


### Error

```python3
Source:
https://github.com/PrefectHQ/prefect/blob/64090acb3aee2da633d3c2bd47cc72c51d3b1bd4/src/prefect/cli/cloud/__init__.py#L368
```


### Versions

```Text
Version:             2.16.9
API version:         0.8.4
Python version:      3.12.2
Git commit:          083def52
Built:               Thu, Apr 4, 2024 3:11 PM
OS/Arch:             darwin/arm64
Profile:             sandbox-jeff
Server type:         cloud
```
```


### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/src/prefect/cli/cloud/__init__.py b/src/prefect/cli/cloud/__init__.py
--- a/src/prefect/cli/cloud/__init__.py
+++ b/src/prefect/cli/cloud/__init__.py
@@ -367,9 +367,6 @@ async def login(
     if current_profile_is_logged_in:
         app.console.print("It looks like you're already authenticated on this profile.")
         if is_interactive():
-            app.console.print(
-                "It looks like you're already authenticated on this profile."
-            )
             should_reauth = typer.confirm(
                 "? Would you like to reauthenticate?", default=False
             )


Test patch: