Niall O'Riordan
02/03/2025, 4:33 PMrun_deployment
function but I receive an error specifying that the deployment doesn't exist as its looking in the wrong workspace
from prefect.deployments import run_deployment
run_deployment(name="a1234", timeout=0, as_subflow=False)
This raises the following error:
prefect.exceptions.PrefectHTTPStatusError: Client error '404 Not Found' for url '<https://api.prefect.cloud/api/accounts/><my-account>/workspaces/<current-workspace-not-the-target-workspace>/deployments/a1234'
Response: {'detail': 'Deployment not found'}
For more information check: <https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404>
Marvin
02/03/2025, 4:34 PMrun_deployment
function is aware of the correct workspace context. The error you encountered indicates that it's looking for the deployment in the current workspace instead of the target one.
Here's how you can specify the correct workspace:
1. Set the Workspace Context: You need to configure your Prefect client to use the desired workspace. This can be done by setting the appropriate environment variables or configuration before calling run_deployment
.
2. Use the Prefect Client: You might need to interact with the Prefect client directly to switch workspaces. Unfortunately, the documentation excerpts didn't provide a direct method, but typically you would:
- Set the PREFECT_API_URL
to point to the correct workspace.
- Use the Prefect client to authenticate and switch workspaces.
3. Double-check Deployment Name: Ensure that the deployment name is correct and exists in the target workspace.
For further details, you might want to consult the Prefect documentation on deployment management and CI/CD practices.
If you continue to face issues, consider reviewing your workspace configuration and ensuring that your environment is set up to access the correct workspace.Niall O'Riordan
02/03/2025, 4:48 PMfrom prefect.deployments import run_deployment
run_deployment(name="a1234", timeout=0, as_subflow=False)
Marvin
02/03/2025, 4:48 PMrun_deployment
.
Here's a conceptual example of how you might adjust your code:
python
from prefect import get_client
from prefect.deployments import run_deployment
# Configure the Prefect client to use the target workspace
client = get_client()
client.api_url = "<https://api.prefect.cloud/api/accounts/<your-account-id>/workspaces/<target-workspace-id>>"
# Now run the deployment in the specified workspace
run_deployment(name="a1234", timeout=0, as_subflow=False)
### Steps to Follow:
1. Get the Account and Workspace IDs: You'll need to know the account ID and the workspace ID for the target workspace. These can be found in your Prefect Cloud settings.
2. Set the API URL: Update the client.api_url
with the correct account and workspace IDs.
3. Run the Deployment: Call run_deployment
after setting the client configuration to ensure it triggers in the correct workspace.
For more specific instructions, it might be helpful to consult the Prefect documentation on workspaces and connecting to Prefect Cloud. If you have access to Prefect's support or community forums, they might provide additional guidance tailored to your setup.Niall O'Riordan
02/03/2025, 4:57 PMMarvin
02/03/2025, 4:58 PMbash
prefect cloud workspace ls
2. Set Active Workspace: Use the CLI to set the desired workspace as the active one.
bash
prefect cloud workspace set --workspace <workspace-name>
3. Run the Deployment: Once the workspace is set, you can run your deployment as intended.
python
from prefect.deployments import run_deployment
run_deployment(name="a1234", timeout=0, as_subflow=False)
By setting the workspace using the Prefect CLI, you ensure that the run_deployment
function operates within the correct workspace context. For more information, you can refer to the Prefect Cloud connection documentation.Nate
02/03/2025, 4:58 PMNate
02/03/2025, 4:58 PMMarvin
02/03/2025, 4:58 PMtemporary_settings
context manager wasn't covered in the Prefect 2.x documentation excerpts I found. However, if you want to temporarily change the context or settings, you might consider using environment variables or directly interacting with the Prefect client configuration, although these methods weren't explicitly detailed in the documentation.
For now, I recommend using the Prefect CLI to set the workspace as previously described. If you have any specific context manager in mind or additional documentation, please let me know, and I can assist further. Alternatively, you could explore Prefect's GitHub repository or community forums for more insights on this feature.Nate
02/03/2025, 4:58 PMNate
02/03/2025, 4:59 PMfrom prefect.settings import PREFECT_API_URL, temporary_settings
with temporary_settings({PREFECT_API_URL: <new value>}):
# call run_deployment
Niall O'Riordan
02/03/2025, 4:59 PMNiall O'Riordan
02/03/2025, 5:43 PMprefect.exceptions.PrefectHTTPStatusError: Client error '404 Not Found' for url '<https://api.prefect.cloud/api/accounts/123/workspaces/abc4/deployments/name/my_flow_name/my_deployment_name>'
or
prefect.exceptions.PrefectHTTPStatusError: Client error '404 Not Found' for url '<https://api.prefect.cloud/api/accounts/123/workspaces/abc4/deployments/def5>'
This matches the url in the Prefect 2 UI:
<https://app.prefect.cloud/account/123/workspace/abc4/deployments/deployment/def5>
I have tested it with a deployment in the same workspace without any issuesNate
02/03/2025, 5:44 PMNiall O'Riordan
02/03/2025, 5:52 PMNiall O'Riordan
02/03/2025, 6:06 PM