This is an automated email from the ASF dual-hosted git repository.

bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new d9a40de38f6 Render object enum values in the trigger form dropdowns 
(#76606)
d9a40de38f6 is described below

commit d9a40de38f6996d13b3d454fd4f297a6e7402965
Author: Software Developer <[email protected]>
AuthorDate: Wed Nov 18 16:35:21 2026 +0100

    Render object enum values in the trigger form dropdowns (#76606)
    
    * render object enum values in the trigger form dropdowns
    
    * addressing PR remarks.
    
    * addressing PR remarks.
    
    * fixing pipeline
---
 airflow-core/docs/core-concepts/params.rst         |  19 +++-
 .../example_dags/example_params_ui_tutorial.py     |  18 ++++
 .../components/FlexibleForm/FieldDropdown.test.tsx |  94 +++++++++++++++-
 .../src/components/FlexibleForm/FieldDropdown.tsx  |  35 +++---
 .../FlexibleForm/FieldMultiSelect.test.tsx         | 119 +++++++++++++++++++++
 .../components/FlexibleForm/FieldMultiSelect.tsx   |  36 ++++---
 .../src/components/FlexibleForm/FieldMultiType.tsx |   7 +-
 .../ui/src/components/FlexibleForm/FieldObject.tsx |   3 +-
 .../components/FlexibleForm/FieldSelector.test.tsx |  36 +++++++
 .../src/components/FlexibleForm/FieldSelector.tsx  |   2 +-
 .../src/components/FlexibleForm/FlexibleForm.tsx   |   5 +-
 .../src/components/FlexibleForm/getEnumValueKey.ts |  72 +++++++++++++
 .../src/airflow/ui/src/queries/useDagParams.ts     |   6 +-
 .../src/airflow/ui/src/queries/useParamStore.ts    |   6 +-
 airflow-core/src/airflow/ui/src/utils/hitl.ts      |  14 +--
 15 files changed, 407 insertions(+), 65 deletions(-)

diff --git a/airflow-core/docs/core-concepts/params.rst 
b/airflow-core/docs/core-concepts/params.rst
index c192ee639ec..78314893ec6 100644
--- a/airflow-core/docs/core-concepts/params.rst
+++ b/airflow-core/docs/core-concepts/params.rst
@@ -330,12 +330,23 @@ The following features are supported in the Trigger UI 
Form:
         * - ``object``
           - | Generates a JSON entry field with
             | text validation.
-          - | The HTML form does only validate the syntax of the
-            | JSON input. In order to validate the content for
-            | specific structures take a look to the
-            | `JSON Schema Object details 
<https://json-schema.org/understanding-json-schema/reference/object.html>`_.
+          - * | The HTML form does only validate the syntax of the
+              | JSON input. In order to validate the content for
+              | specific structures take a look to the
+              | `JSON Schema Object details 
<https://json-schema.org/understanding-json-schema/reference/object.html>`_.
+            * | ``enum=[{"name": "dev"}, {"name": "prod"}]``:
+              | Generates a drop-down select list of objects;
+              | the selected object is passed as-is.
+            * | ``values_display={json.dumps({"name": "dev"}): 
"Development"}``:
+              | Labels for object choices are keyed by the
+              | JSON text of the object. Spacing and key
+              | order do not matter, so ``json.dumps()`` of
+              | the enum entry is the easiest way to write
+              | the key.
           - ``Param({"key": "value"}, type=["object", "null"])``
 
+            ``Param({"name": "dev"}, type="object", enum=[{"name": "dev"}, 
{"name": "prod"}])``
+
         * - ``null``
           - | Specifies that no content is expected.
             | Standalone this does not make much sense
diff --git 
a/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py 
b/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py
index e79ea943197..0dfd4be1130 100644
--- a/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py
+++ b/airflow-core/src/airflow/example_dags/example_params_ui_tutorial.py
@@ -39,6 +39,10 @@ def _get_script_interfaces_from_config() -> list[str]:
 
 
 SCRIPT_INTERFACES = _get_script_interfaces_from_config()
+DEPLOY_ENVIRONMENTS = [
+    {"name": "dev", "replicas": 1},
+    {"name": "prod", "replicas": 5},
+]
 
 with DAG(
     dag_id=Path(__file__).stem,
@@ -188,6 +192,20 @@ with DAG(
             },
             section="Drop-Downs and selection lists",
         ),
+        # Enum values can also be objects. Labels for them are keyed by the 
JSON text of the object,
+        # any spacing and key order is accepted, so json.dumps() is the 
easiest way to write the key.
+        "pick_environment": Param(
+            DEPLOY_ENVIRONMENTS[0],
+            type="object",
+            title="Select an Environment",
+            description="Object enum values are shown as a drop down and the 
selected object is passed as-is.",
+            enum=DEPLOY_ENVIRONMENTS,
+            values_display={
+                json.dumps(DEPLOY_ENVIRONMENTS[0]): "Development (1 replica)",
+                json.dumps(DEPLOY_ENVIRONMENTS[1]): "Production (5 replicas)",
+            },
+            section="Drop-Downs and selection lists",
+        ),
         # If you want to have a list box with proposals but not enforcing a 
fixed list
         # then you can use the examples feature of JSON schema
         "proposals": Param(
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.test.tsx
 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.test.tsx
index 7849de17d75..46c6c5e5886 100644
--- 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.test.tsx
+++ 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.test.tsx
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { render, screen } from "@testing-library/react";
+import { fireEvent, render, screen } from "@testing-library/react";
 import { describe, it, expect, beforeEach, vi } from "vitest";
 
 import { Wrapper } from "src/utils/Wrapper";
@@ -133,6 +133,98 @@ describe("FieldDropdown", () => {
     expect(screen.getByRole("combobox")).toBeDefined();
   });
 
+  it("renders the selected object enum value by its JSON form", () => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: { enum: envs, type: "object" },
+      value: envs[1],
+    };
+
+    render(<FieldDropdown name="test_param" onUpdate={vi.fn()} />, { wrapper: 
Wrapper });
+
+    expect(screen.getByText(JSON.stringify(envs[1]))).toBeDefined();
+  });
+
+  it("labels object enum options via values_display keyed by their JSON form", 
() => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: {
+        enum: envs,
+        type: "object",
+        values_display: { [JSON.stringify(envs[0])]: "Development" },
+      },
+      value: envs[0],
+    };
+
+    render(<FieldDropdown name="test_param" onUpdate={vi.fn()} />, { wrapper: 
Wrapper });
+
+    expect(screen.getByText("Development")).toBeDefined();
+  });
+
+  it("labels object enum options when the values_display key differs in 
spacing and key order", () => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: {
+        enum: envs,
+        type: "object",
+        values_display: { '{"replicas": 1, "name": "dev"}': "Development" },
+      },
+      value: envs[0],
+    };
+
+    render(<FieldDropdown name="test_param" onUpdate={vi.fn()} />, { wrapper: 
Wrapper });
+
+    expect(screen.getByText("Development")).toBeDefined();
+  });
+
+  it("selects the current object value regardless of its key order", () => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: { enum: envs, type: "object" },
+      value: JSON.parse('{"replicas": 5, "name": "prod"}') as unknown,
+    };
+
+    render(<FieldDropdown name="test_param" onUpdate={vi.fn()} />, { wrapper: 
Wrapper });
+
+    expect(screen.getByText(JSON.stringify(envs[1]))).toBeDefined();
+  });
+
+  it("stores the original object when an object enum option is selected", () 
=> {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: { enum: envs, type: "object" },
+      value: null,
+    };
+
+    render(<FieldDropdown name="test_param" onUpdate={vi.fn()} />, { wrapper: 
Wrapper });
+
+    fireEvent.keyDown(screen.getByRole("combobox"), { key: "ArrowDown" });
+    fireEvent.click(screen.getByText(JSON.stringify(envs[1])));
+
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+    expect(mockParamsDict.test_param.value).toStrictEqual(envs[1]);
+  });
+
   it("preserves numeric type when selecting a number enum value (prevents 400 
Bad Request)", () => {
     mockParamsDict.test_param = {
       schema: {
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.tsx 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.tsx
index f5cf4fe7690..6602e510942 100644
--- a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.tsx
+++ b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDropdown.tsx
@@ -19,27 +19,25 @@
 import { type SingleValue, Select as ReactSelect } from "chakra-react-select";
 import { useTranslation } from "react-i18next";
 
+import type { ParamValue } from "src/queries/useDagParams";
 import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
 
 import type { FlexibleFormElementProps } from ".";
+import { getEnumValueKey, lookupValuesDisplay } from "./getEnumValueKey";
 
 const NULL_STRING_VALUE = "__null__";
 
-const labelLookup = (
-  key: boolean | number | string | null,
-  valuesDisplay: Record<string, string> | undefined,
-): string => {
-  if (valuesDisplay && typeof valuesDisplay === "object") {
-    const stringKey = key === null ? "null" : String(key);
+const toOptionValue = (value: ParamValue): string =>
+  value === null ? NULL_STRING_VALUE : getEnumValueKey(value);
 
-    return valuesDisplay[stringKey] ?? valuesDisplay.None ?? stringKey;
-  }
+const labelLookup = (key: ParamValue, valuesDisplay: Record<string, string> | 
undefined): string => {
+  const stringKey = key === null ? "null" : getEnumValueKey(key);
 
-  return key === null ? "null" : String(key);
+  return (
+    lookupValuesDisplay(stringKey, valuesDisplay) ?? 
lookupValuesDisplay("None", valuesDisplay) ?? stringKey
+  );
 };
 
-const enumTypes = ["string", "number", "integer"];
-
 export const FieldDropdown = ({ name, namespace = "default", onUpdate }: 
FlexibleFormElementProps) => {
   const { t: translate } = useTranslation("components");
   const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
@@ -48,15 +46,10 @@ export const FieldDropdown = ({ name, namespace = 
"default", onUpdate }: Flexibl
   const options =
     param.schema.enum?.map((value) => ({
       label: labelLookup(value, param.schema.values_display),
-      value: String(value ?? NULL_STRING_VALUE),
+      value: toOptionValue(value),
     })) ?? [];
 
-  const currentValue =
-    param.value === null
-      ? (options.find((opt) => opt.value === NULL_STRING_VALUE) ?? null)
-      : enumTypes.includes(typeof param.value)
-        ? (options.find((opt) => opt.value === String(param.value)) ?? null)
-        : null;
+  const currentValue = options.find((opt) => opt.value === 
toOptionValue(param.value)) ?? null;
 
   const handleChange = (
     selected: SingleValue<{
@@ -68,11 +61,9 @@ export const FieldDropdown = ({ name, namespace = "default", 
onUpdate }: Flexibl
       if (!selected || selected.value === NULL_STRING_VALUE) {
         paramsDict[name].value = null;
       } else {
-        // Map the string value back to the original typed enum value (e.g. 
number, string)
+        // Map the string value back to the original typed enum value (e.g. 
number, object)
         // so that backend validation receives the correct type.
-        const originalValue = param.schema.enum?.find(
-          (enumVal) => String(enumVal ?? NULL_STRING_VALUE) === selected.value,
-        );
+        const originalValue = param.schema.enum?.find((enumVal) => 
toOptionValue(enumVal) === selected.value);
 
         paramsDict[name].value = originalValue ?? selected.value;
       }
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiSelect.test.tsx
 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiSelect.test.tsx
new file mode 100644
index 00000000000..17c577e3e82
--- /dev/null
+++ 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiSelect.test.tsx
@@ -0,0 +1,119 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { fireEvent, render, screen } from "@testing-library/react";
+import { describe, it, expect, beforeEach, vi } from "vitest";
+
+import { Wrapper } from "src/utils/Wrapper";
+
+import { FieldMultiSelect } from "./FieldMultiSelect";
+
+type MockParam = { schema: Record<string, unknown>; value: unknown };
+const mockParamsDict: Record<string, MockParam> = {};
+const mockSetParamsDict = vi.fn();
+
+vi.mock("src/queries/useParamStore", () => ({
+  paramPlaceholder: {
+    schema: {},
+    value: null,
+  },
+  useParamStore: () => ({
+    disabled: false,
+    paramsDict: mockParamsDict,
+    setParamsDict: mockSetParamsDict,
+  }),
+}));
+
+describe("FieldMultiSelect", () => {
+  beforeEach(() => {
+    vi.clearAllMocks();
+    Object.keys(mockParamsDict).forEach((key) => {
+      // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
+      delete mockParamsDict[key];
+    });
+  });
+
+  it("renders selected object values by their JSON form", () => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: { enum: envs, type: "array" },
+      value: [envs[0]],
+    };
+
+    render(<FieldMultiSelect name="test_param" onUpdate={vi.fn()} />, { 
wrapper: Wrapper });
+
+    expect(screen.getByText(JSON.stringify(envs[0]))).toBeDefined();
+  });
+
+  it("labels object choices when the values_display key differs in spacing and 
key order", () => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: {
+        enum: envs,
+        type: "array",
+        values_display: { '{"replicas": 1, "name": "dev"}': "Development" },
+      },
+      value: [envs[0]],
+    };
+
+    render(<FieldMultiSelect name="test_param" onUpdate={vi.fn()} />, { 
wrapper: Wrapper });
+
+    expect(screen.getByText("Development")).toBeDefined();
+  });
+
+  it("stores the original objects when object choices are selected", () => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: { enum: envs, type: "array" },
+      value: null,
+    };
+
+    render(<FieldMultiSelect name="test_param" onUpdate={vi.fn()} />, { 
wrapper: Wrapper });
+
+    fireEvent.keyDown(screen.getByRole("combobox"), { key: "ArrowDown" });
+    fireEvent.click(screen.getByText(JSON.stringify(envs[1])));
+
+    expect(mockParamsDict.test_param.value).toStrictEqual([envs[1]]);
+  });
+
+  it("preserves numeric type when selecting a number choice", () => {
+    mockParamsDict.test_param = {
+      schema: { enum: [1, 2, 3], type: "array" },
+      value: null,
+    };
+
+    render(<FieldMultiSelect name="test_param" onUpdate={vi.fn()} />, { 
wrapper: Wrapper });
+
+    fireEvent.keyDown(screen.getByRole("combobox"), { key: "ArrowDown" });
+    fireEvent.click(screen.getByText("2"));
+
+    expect(mockParamsDict.test_param.value).toStrictEqual([2]);
+  });
+});
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiSelect.tsx 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiSelect.tsx
index ecc236c3cfd..a158053c977 100644
--- 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiSelect.tsx
+++ 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiSelect.tsx
@@ -21,26 +21,30 @@ import { useState } from "react";
 import { type MultiValue, Select as ReactSelect } from "chakra-react-select";
 import { useTranslation } from "react-i18next";
 
+import type { ParamValue } from "src/queries/useDagParams";
 import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
 
 import type { FlexibleFormElementProps } from ".";
+import { getEnumValueKey, lookupValuesDisplay } from "./getEnumValueKey";
 
 const labelLookup = (key: string, valuesDisplay: Record<string, string> | 
undefined): string =>
-  valuesDisplay && typeof valuesDisplay === "object" ? (valuesDisplay[key] ?? 
key) : key;
+  lookupValuesDisplay(key, valuesDisplay) ?? key;
 
 export const FieldMultiSelect = ({ name, namespace = "default", onUpdate }: 
FlexibleFormElementProps) => {
   const { t: translate } = useTranslation("components");
   const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
   const param = paramsDict[name] ?? paramPlaceholder;
 
+  const choices = (param.schema.examples ?? param.schema.enum)?.filter((value) 
=> value !== null) ?? [];
+
+  const toOption = (value: ParamValue) => ({
+    label: labelLookup(getEnumValueKey(value), param.schema.values_display),
+    value: getEnumValueKey(value),
+  });
+
   // Initialize `selectedOptions` directly from `paramsDict`
   const [selectedOptions, setSelectedOptions] = useState(
-    Array.isArray(param.value)
-      ? (param.value as Array<string>).map((value) => ({
-          label: labelLookup(value, param.schema.values_display),
-          value,
-        }))
-      : [],
+    Array.isArray(param.value) ? param.value.map(toOption) : [],
   );
 
   // Handle changes to the select field
@@ -55,13 +59,18 @@ export const FieldMultiSelect = ({ name, namespace = 
"default", onUpdate }: Flex
     setSelectedOptions(updatedOptions);
 
     // "undefined" values are removed from params, so we set it to null to 
avoid falling back to DAG defaults.
-    const newValueArray = updatedOptions.length ? updatedOptions.map((option) 
=> option.value) : null;
+    // Map option keys back to the original typed choices so backend 
validation receives the correct types.
+    const newValueArray = updatedOptions.length
+      ? updatedOptions.map(
+          (option) => choices.find((choice) => getEnumValueKey(choice) === 
option.value) ?? option.value,
+        )
+      : null;
 
     if (paramsDict[name]) {
       paramsDict[name].value = newValueArray;
     }
     setParamsDict(paramsDict);
-    onUpdate(String(newValueArray));
+    onUpdate(String(updatedOptions.map((option) => option.value)));
   };
 
   return (
@@ -78,14 +87,7 @@ export const FieldMultiSelect = ({ name, namespace = 
"default", onUpdate }: Flex
       menuPosition="fixed"
       name={`element_${name}`}
       onChange={handleChange}
-      options={
-        (param.schema.examples ?? param.schema.enum)
-          ?.filter((value): value is boolean | number | string => value !== 
null)
-          .map((value) => ({
-            label: labelLookup(String(value), param.schema.values_display),
-            value: String(value),
-          })) ?? []
-      }
+      options={choices.map(toOption)}
       placeholder={translate("flexibleForm.placeholderMulti")}
       size="sm"
       value={selectedOptions}
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiType.tsx 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiType.tsx
index 2dd15724412..076dd1d3c57 100644
--- a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiType.tsx
+++ b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldMultiType.tsx
@@ -20,6 +20,7 @@ import { useState } from "react";
 
 import { Textarea } from "@chakra-ui/react";
 
+import type { ParamValue } from "src/queries/useDagParams";
 import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
 
 import type { FlexibleFormElementProps } from ".";
@@ -48,7 +49,7 @@ export const FieldMultiType = ({ name, namespace = "default", 
onUpdate }: Flexib
   const stringIsAllowed = nonNullTypes.includes("string");
 
   const storedDisplay =
-    param.value === null || param.value === undefined
+    param.value === null
       ? ""
       : typeof param.value === "string"
         ? param.value
@@ -73,11 +74,11 @@ export const FieldMultiType = ({ name, namespace = 
"default", onUpdate }: Flexib
       return;
     }
 
-    let resolved: unknown;
+    let resolved: ParamValue = null;
     let matched = false;
 
     try {
-      const parsed = JSON.parse(value) as unknown;
+      const parsed = JSON.parse(value) as ParamValue;
 
       if (matchesSchemaType(parsed, nonNullTypes)) {
         resolved = parsed;
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldObject.tsx 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldObject.tsx
index 3fcbcd779a4..5d547b6d7f7 100644
--- a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldObject.tsx
+++ b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldObject.tsx
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+import type { ParamValue } from "src/queries/useDagParams";
 import { paramPlaceholder, useParamStore } from "src/queries/useParamStore";
 
 import type { FlexibleFormElementProps } from ".";
@@ -28,7 +29,7 @@ export const FieldObject = ({ name, namespace = "default", 
onUpdate }: FlexibleF
   const handleChange = (value: string) => {
     try {
       // "undefined" values are removed from params, so we set it to null to 
avoid falling back to DAG defaults.
-      const parsedValue = value === "" ? null : (JSON.parse(value) as JSON);
+      const parsedValue = value === "" ? null : (JSON.parse(value) as 
ParamValue);
 
       if (paramsDict[name]) {
         paramsDict[name].value = parsedValue;
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.test.tsx
 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.test.tsx
index 8d6efe6a04e..d4bc53a323a 100644
--- 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.test.tsx
+++ 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.test.tsx
@@ -85,3 +85,39 @@ describe("FieldSelector array routing", () => {
     expect(screen.queryByRole("combobox")).toBeNull();
   });
 });
+
+describe("FieldSelector enum routing", () => {
+  beforeEach(() => {
+    Object.keys(mockParamsDict).forEach((key) => {
+      // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
+      delete mockParamsDict[key];
+    });
+  });
+
+  it("renders a dropdown for an object param with enum choices", () => {
+    const envs = [
+      { name: "dev", replicas: 1 },
+      { name: "prod", replicas: 5 },
+    ];
+
+    mockParamsDict.test_param = {
+      schema: { enum: envs, type: "object" },
+      value: envs[0],
+    };
+
+    render(<FieldSelector name="test_param" onUpdate={vi.fn()} />, { wrapper: 
Wrapper });
+
+    expect(screen.getByRole("combobox")).toBeDefined();
+  });
+
+  it("renders the JSON editor for an object param without enum", () => {
+    mockParamsDict.test_param = {
+      schema: { type: "object" },
+      value: { name: "dev" },
+    };
+
+    render(<FieldSelector name="test_param" onUpdate={vi.fn()} />, { wrapper: 
Wrapper });
+
+    expect(screen.queryByRole("combobox")).toBeNull();
+  });
+});
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.tsx 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.tsx
index 59e5fe67202..d15c90bc88a 100644
--- a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.tsx
+++ b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldSelector.tsx
@@ -72,7 +72,7 @@ const isFieldDateTime = (fieldType: string, fieldSchema: 
ParamSchema) =>
 const isFieldDuration = (fieldType: string, fieldSchema: ParamSchema) =>
   fieldType === "string" && fieldSchema.format === "duration";
 
-const enumTypes = ["null", "string", "number", "integer"];
+const enumTypes = ["null", "string", "number", "integer", "object"];
 
 const isFieldDropdown = (fieldType: string, fieldSchema: ParamSchema) =>
   enumTypes.includes(fieldType) && Array.isArray(fieldSchema.enum);
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FlexibleForm.tsx 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FlexibleForm.tsx
index e9c197445fe..1ca1fa8e70f 100644
--- a/airflow-core/src/airflow/ui/src/components/FlexibleForm/FlexibleForm.tsx
+++ b/airflow-core/src/airflow/ui/src/components/FlexibleForm/FlexibleForm.tsx
@@ -57,10 +57,7 @@ const computeSectionErrors = (
   const errors = new Map<string, boolean>();
 
   Object.values(params).forEach((element) => {
-    if (
-      isRequired(element) &&
-      (element.value === null || element.value === undefined || element.value 
=== "")
-    ) {
+    if (isRequired(element) && (element.value === null || element.value === 
"")) {
       errors.set(element.schema.section ?? defaultSection, true);
     }
   });
diff --git 
a/airflow-core/src/airflow/ui/src/components/FlexibleForm/getEnumValueKey.ts 
b/airflow-core/src/airflow/ui/src/components/FlexibleForm/getEnumValueKey.ts
new file mode 100644
index 00000000000..8363be45b29
--- /dev/null
+++ b/airflow-core/src/airflow/ui/src/components/FlexibleForm/getEnumValueKey.ts
@@ -0,0 +1,72 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import type { ParamValue } from "src/queries/useDagParams";
+
+const sortKeys = (value: ParamValue): ParamValue => {
+  if (Array.isArray(value)) {
+    return value.map(sortKeys);
+  }
+
+  return typeof value === "object" && value !== null
+    ? Object.fromEntries(
+        Object.keys(value)
+          .sort()
+          .map((key) => [key, sortKeys(value[key] as ParamValue)]),
+      )
+    : value;
+};
+
+/**
+ * String identity of an enum entry, also used as the `values_display` lookup 
key.
+ * Objects and arrays are keyed by their JSON form with sorted keys and no 
whitespace, so structurally
+ * equal values share one key regardless of how they were written; entries 
that differ only in key order
+ * collapse into a single option.
+ */
+export const getEnumValueKey = (value: ParamValue): string =>
+  typeof value === "object" && value !== null ? 
JSON.stringify(sortKeys(value)) : String(value);
+
+const toCanonicalKey = (key: string): string => {
+  try {
+    return getEnumValueKey(JSON.parse(key) as ParamValue);
+  } catch {
+    return key;
+  }
+};
+
+/**
+ * Label for an enum key. Dag authors write object keys as JSON text 
(`json.dumps(...)`), so the lookup
+ * accepts any spacing and key order rather than requiring the exact canonical 
form.
+ */
+export const lookupValuesDisplay = (
+  key: string,
+  valuesDisplay: Record<string, string> | undefined,
+): string | undefined => {
+  if (!valuesDisplay || typeof valuesDisplay !== "object") {
+    return undefined;
+  }
+  if (key in valuesDisplay) {
+    return valuesDisplay[key];
+  }
+  if (!key.startsWith("{") && !key.startsWith("[")) {
+    return undefined;
+  }
+  const match = Object.keys(valuesDisplay).find((displayKey) => 
toCanonicalKey(displayKey) === key);
+
+  return match === undefined ? undefined : valuesDisplay[match];
+};
diff --git a/airflow-core/src/airflow/ui/src/queries/useDagParams.ts 
b/airflow-core/src/airflow/ui/src/queries/useDagParams.ts
index 776a03d71a5..7a7206b8bb4 100644
--- a/airflow-core/src/airflow/ui/src/queries/useDagParams.ts
+++ b/airflow-core/src/airflow/ui/src/queries/useDagParams.ts
@@ -24,17 +24,19 @@ import { toaster } from "src/system-components";
 
 export type ParamsSpec = Record<string, ParamSpec>;
 
+export type ParamValue = Array<ParamValue> | boolean | number | string | { 
[key: string]: ParamValue } | null;
+
 export type ParamSpec = {
   description: string | null;
   schema: ParamSchema;
-  value: unknown;
+  value: ParamValue;
 };
 
 export type ParamSchema = {
   // TODO define the structure on API as generated code
   const: string | undefined;
   description_md: string | undefined;
-  enum: Array<boolean | number | string | null> | undefined;
+  enum: Array<ParamValue> | undefined;
   examples: Array<string> | undefined;
   format: string | undefined;
   items: Record<string, unknown> | undefined;
diff --git a/airflow-core/src/airflow/ui/src/queries/useParamStore.ts 
b/airflow-core/src/airflow/ui/src/queries/useParamStore.ts
index 38200ad76b5..6f5c704c161 100644
--- a/airflow-core/src/airflow/ui/src/queries/useParamStore.ts
+++ b/airflow-core/src/airflow/ui/src/queries/useParamStore.ts
@@ -18,7 +18,7 @@
  */
 import { create } from "zustand";
 
-import type { ParamsSpec, ParamSpec } from "src/queries/useDagParams";
+import type { ParamsSpec, ParamSpec, ParamValue } from 
"src/queries/useDagParams";
 
 export const paramPlaceholder: ParamSpec = {
   description: null,
@@ -65,7 +65,7 @@ const createParamStore = () =>
           return {};
         }
 
-        const parsedConf = JSON.parse(confString) as Record<string, unknown>;
+        const parsedConf = JSON.parse(confString) as Record<string, 
ParamValue>;
         const baseDict =
           Object.keys(state.initialParamDict).length > 0 ? 
state.initialParamDict : state.paramsDict;
 
@@ -81,7 +81,7 @@ const createParamStore = () =>
               {
                 description: baseParam.description ?? null,
                 schema: baseParam.schema,
-                value: parsedConf[key],
+                value: parsedConf[key] ?? null,
               },
             ]);
           }
diff --git a/airflow-core/src/airflow/ui/src/utils/hitl.ts 
b/airflow-core/src/airflow/ui/src/utils/hitl.ts
index 4fcd47ed5d1..02b3b378556 100644
--- a/airflow-core/src/airflow/ui/src/utils/hitl.ts
+++ b/airflow-core/src/airflow/ui/src/utils/hitl.ts
@@ -20,7 +20,7 @@ import type { TFunction } from "i18next";
 
 import type { HITLDetail, HITLDetailHistory, TaskInstanceState } from 
"openapi/requests/types.gen";
 
-import type { ParamSchema, ParamSpec, ParamsSpec } from 
"src/queries/useDagParams";
+import type { ParamSchema, ParamSpec, ParamsSpec, ParamValue } from 
"src/queries/useDagParams";
 
 export type HITLResponseParams = {
   chosen_options?: Array<string>;
@@ -113,7 +113,7 @@ export const getHITLParamsDict = (
       // If the task is not multiple, we only show the first option
       value:
         getChosenOptionsValue(hitlDetail) ??
-        (hitlDetail.multiple ? preloadedHITLOptions : preloadedHITLOptions[0]),
+        (hitlDetail.multiple ? preloadedHITLOptions : (preloadedHITLOptions[0] 
?? null)),
     };
   }
 
@@ -135,7 +135,9 @@ export const getHITLParamsDict = (
 
       // Values arrive as stored JSON, so an object param's value is already 
an object. A string is
       // never parsed: a JSON-looking string would render as "[object Object]" 
and go back as an object.
-      const finalValue = hitlDetail.params_input?.[key] ?? (isWrapped ? 
paramData.value : value);
+      const finalValue = (hitlDetail.params_input?.[key] ?? (isWrapped ? 
paramData.value : value)) as
+        | ParamValue
+        | undefined;
 
       const description: string =
         paramData && typeof paramData.description === "string" ? 
paramData.description : "";
@@ -172,7 +174,7 @@ export const getHITLParamsDict = (
       paramsDict[key] = {
         description,
         schema,
-        value: finalValue ?? paramData?.value,
+        value: finalValue ?? paramData?.value ?? null,
       };
     });
   }
@@ -188,9 +190,7 @@ export const getHITLFormData = (paramsDict: ParamsSpec, 
option?: string): HITLRe
     if (typeof chosenOptionsValue === "string" && chosenOptionsValue) {
       chosenOptions = [chosenOptionsValue];
     } else if (Array.isArray(chosenOptionsValue) && chosenOptionsValue.length 
> 0) {
-      chosenOptions = chosenOptionsValue.filter(
-        (value): value is string => value !== null && value !== undefined,
-      );
+      chosenOptions = chosenOptionsValue.filter((value): value is string => 
typeof value === "string");
     }
   } else {
     chosenOptions = [option];

Reply via email to