anzinmhd opened a new pull request, #75496: URL: https://github.com/apache/airflow/pull/75496
Saving an XCom through the UI can unintentionally change its stored type. This PR preserves the stored value’s type when loading the edit form and retains its JSON representation when saving. ### Problem For an XCom containing the string `"123"`, opening Edit and clicking Save without changing anything replaces it with the number `123`. The problem is not limited to unchanged saves. The editor loses the distinction between a string and another JSON type, so editing a string to another JSON-looking value can also result in an unintended type conversion. For example, entering unquoted `456` after the editor loaded a string can save a number rather than the intended string. There are two opportunities for unintended conversion: 1. The edit form requests `deserialize=true`. The API can parse a stored JSON-looking string into another type before returning it to the editor. 2. The form populates the JSON editor with unquoted string content, then calls `JSON.parse()` when saving. Strings containing JSON literals can consequently become numbers, booleans, objects, arrays, or null. An unchanged save provides a minimal reproduction: it demonstrates that the stored type changes without the user requesting any modification. ### Fix Load the edit form from the stored value using `deserialize=false` and `stringify=false`, then populate the JSON editor with `JSON.stringify()`. These changes address both conversion points: - The read request preserves the stored value’s type. - JSON formatting preserves string quotation marks and escaping, allowing the existing save parser to reconstruct the original value. For example: | Stored value | Editor content | After an unchanged save | | --- | --- | --- | | String `"123"` | `"123"` with quotation marks | String `"123"` | | Number `123` | `123` without quotation marks | Number `123` | The editor now makes the type distinction explicit. Users can retain quotation marks when editing a string or deliberately remove them to change its type. The backend API and display-only XCom view are unchanged. ### Steps to reproduce 1. Create a manually triggered Dag with a TaskFlow task that returns the string `"123"`. 2. Trigger the Dag and wait for the task to succeed. 3. Open the task’s XCom tab and locate `return_value`. 4. Open the individual XCom API URL with `deserialize=false&stringify=false`. 5. Confirm that the response contains `"value":"123"`. 6. Return to the UI, open Edit XCom, and click Save without changing anything. 7. Reload the same API URL. **Before:** The response contains `"value":123`. Saving unchanged has replaced the stored string with a number. **After:** The response still contains `"value":"123"`. The stored string is preserved. Using the same raw-response parameters before and after distinguishes a stored-value change from display formatting or response deserialization. ### Tests and validation Added eight regression cases covering: - Numeric-looking strings - Boolean-looking strings - Null-looking strings - Object-looking strings - Array-looking strings - Strings containing quotation marks - Empty strings - Multiline strings The tests verify the read query parameters, the JSON editor content, and the value sent in the update request after saving without edits. Validation completed: - All eight new regression cases fail without the production fix. - All **22 tests across the three XCom test files pass** with the fix. - Targeted ESLint and Prettier checks pass. - TypeScript checking passes. - Manually verified that an unchanged save preserves the string in the API response using `deserialize=false&stringify=false`. The automated regression cases and manual reproduction specifically cover unchanged saves. The broader risk during intentional edits follows from the same conversion path; intentional-edit scenarios have not been separately verified. ### Before Opening Edit and saving without changes converts the stored string `"123"` into the number `123`. https://github.com/user-attachments/assets/b4fa4517-3353-4451-8795-dc91d9aa86b0 ### After The editor retains the string’s JSON quotation marks, and saving without changes preserves `"value":"123"` in the raw API response. https://github.com/user-attachments/assets/00064d14-c7b6-4d40-8121-578c347e27ee --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes — Codex (GPT-6) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
