Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deployment): account for "null" response in parameter_openapi_schema #401

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

mitchnielsen
Copy link
Contributor

@mitchnielsen mitchnielsen commented Mar 4, 2025

Summary

In OSS, the return value for parameter_openapi_schema is "null" instead of an empty map {}.

This leads to an inconsistent value error because the default value is the empty map "{}", but the response from the API tries to set "null".

Closes #399

Closes https://linear.app/prefect/issue/PLA-1204/resoure-prefect-deployment-error-provider-produced-inconsistent-result

Testing

We need to test against both Cloud and OSS to ensure this logic supports both cases.

For Cloud:

terraform {
  required_providers {
    prefect = {
      source = "registry.terraform.io/prefecthq/prefect"
    }
  }
}

# For a cloud instance
provider "prefect" {
  endpoint = "https://api.stg.prefect.dev"
  account_id   = "9a67b081-4f14-4035-b000-1f715f46231b"
  workspace_id = "85bad5d0-48ee-42be-9f72-8a2998512d85"
  api_key = "<redacted>"
}

resource "prefect_flow" "say_hello_flow" {
  name = "mitch-say-hello-flow"
}

resource "prefect_deployment" "hello_flow" {
  name                     = "mitch-hello-flow-deployment"
  flow_id                  = prefect_flow.say_hello_flow.id
  entrypoint               = "flows/hello_ecs_flow.py:say_hello_flow"
  version                  = "0.1"
  enforce_parameter_schema = true
  pull_steps = [
    {
      directory = "/opt/prefect"
      type      = "set_working_directory"
    },
  ]
}

You should be able to successfully apply the plan.

Next, test in OSS by modifying the compose file to match the reported version of Prefect:

diff --git a/compose.yml b/compose.yml
index b111531..b3b8fbd 100644
--- a/compose.yml
+++ b/compose.yml
@@ -4,7 +4,8 @@
 # See ./_about/CONTRIBUTING.md.
 services:
   prefect:
-    image: prefecthq/prefect:3-latest
+    image: prefecthq/prefect:3.2.9-python3.12
     ports:
       - "4200:4200"
     environment:

Then update your Terraform config to point to a local instance:

provider "prefect" {
  endpoint = "http://localhost:4200"
}

You should again be able to successfully apply the plan.

Requirements

General

  • The contributing guide has been read
  • Title follows the conventional commits format
  • Body includes Closes <issue>, if available
  • Relevant labels have been added
  • Draft status is used until ready for review

Code-level changes

  • Unit tests are added/updated
  • Acceptance tests are added/updated (including import tests, when needed)

New or updated resource/datasource

  • Documentation is added (generated by make docs from source code)
    - When applicable, provide a link back to the relevant page in the Prefect documentation site.
  • For resources, the following are added:
    - Resource example under examples/resources/prefect_<name>/resource.tf
    - Import example under examples/resources/prefect_<name>/import.sh
  • For datasources, the following is added:
    - Datasource example under examples/data-sources,resources>/prefect_<name>/data-source.tf

In OSS, the return value for parameter_openapi_schema is "null" instead
of an empty map {}.

This leads to an inconsistent value error because the default value is
the empty map "{}", but the response from the API tries to set "null".

Closes #399
@mitchnielsen mitchnielsen added the bugfix Fixing a bug label Mar 4, 2025
@mitchnielsen mitchnielsen self-assigned this Mar 4, 2025
@mitchnielsen mitchnielsen changed the title Account for "null" response in parameter_openapi_schema fix(deployment): account for "null" response in parameter_openapi_schema Mar 4, 2025
@mitchnielsen mitchnielsen marked this pull request as ready for review March 4, 2025 21:06
@mitchnielsen mitchnielsen requested a review from a team as a code owner March 4, 2025 21:06
@mitchnielsen mitchnielsen merged commit 9383bda into main Mar 4, 2025
7 checks passed
@mitchnielsen mitchnielsen deleted the deployments-fix-openapi-schema branch March 4, 2025 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource: prefect_deployment, Error: Provider produced inconsistent result after apply
3 participants