APIRequest response data types getting mangled in Data object
Bug Description
Server requests come back and the .json() values have correct types (numbers, booleans, strings), but in the component output all of the values are converted to string.
Reproduction
This flow uses postman-echo.com to send a request body which is echoed back, and includes some logger.debug statements:
And we can see from the log outputs, the numbers and booleans are not wrapped in ":
DEBUG 2024-11-08 15:48:37 - DEBUG - <string> - request.json: {'name': 'John Doe', 'age': 30, 'as_of': '2024-11-08T14:30:00Z', 'alive': True, <string>:131
'net_worth': 123.45}
[11/08/24 15:48:38] DEBUG 2024-11-08 15:48:38 - DEBUG - <string> - result: {'args': {}, 'data': {'name': 'John Doe', 'age': 30, 'as_of': '2024-11-08T14:30:00Z', <string>:135
'alive': True, 'net_worth': 123.45}, 'files': {}, 'form': {}, 'headers': {'host': 'postman-echo.com', 'x-request-start':
't=1731080917.687', 'connection': 'close', 'content-length': '100', 'x-forwarded-proto': 'https', 'x-forwarded-port': '443',
'x-amzn-trace-id': 'Root=1-672e32d5-1e222a7f47d068254a1c7cb9', 'accept': '*/*', 'accept-encoding': 'gzip, deflate', 'user-agent':
'python-httpx/0.27.0', 'content-type': 'application/json'}, 'json': {'name': 'John Doe', 'age': 30, 'as_of': '2024-11-08T14:30:00Z',
'alive': True, 'net_worth': 123.45}, 'url': 'https://postman-echo.com/post'}
However if you inspect the output record HTML, the response value has converted these to strings:
{"args":{},"data":{"name":"John Doe","age":"30","as_of":"2024-11-08T14:30:00Z","alive":"True","net_worth":"123.45"},"files":{},"form":{},"headers":{"host":"postman-echo.com","x-request-start":"t=1731080917.687","connection":"close","content-length":"100","x-forwarded-proto":"https","x-forwarded-port":"443","x-amzn-trace-id":"Root=1-672e32d5-1e222a7f47d068254a1c7cb9","accept":"*/*","accept-encoding":"gzip, deflate","user-agent":"python-httpx/0.27.0","content-type":"application/json"},"json":{"name":"John Doe","age":"30","as_of":"2024-11-08T14:30:00Z","alive":"True","net_worth":"123.45"},"url":"https://postman-echo.com/post"}
And in the new dict viewer the values are string.
Expected behavior
Data types should be as they were in the JSON response.
Who can help?
No response
Operating System
Windows
Langflow Version
v1.0.19.dev24
Python Version
3.12
Screenshot
No response
Flow File
The issue you're experiencing, where data types in the APIRequest response are being converted to strings in the component output, is likely due to the serialization process in the make_request method. This method uses json.dumps(data) to serialize the request body into a JSON-formatted string, which converts all data types into their string representations [1].
To address this, you might need to review how the data is being processed after the response is received. The make_request method attempts to parse the response content as JSON and stores it in the result field of the Data object. If the JSON parsing fails, it falls back to storing the response text [1].
Additionally, ensure that any further processing or rendering of the data does not inadvertently convert the data types to strings. You might want to check if there are any specific methods or functions in the codebase that explicitly convert non-string data types to strings, such as data_to_string, document_to_string, or dict_values_to_string [2].
To continue talking to Dosu, mention @dosu.
I suspect the problem is in how the Data object is deserializing the result:
response = await client.request(method, url, headers=headers, json=data, timeout=timeout)
try:
result = response.json()
except Exception: # noqa: BLE001
result = response.text
return Data(
data={
"source": url,
"headers": headers,
"status_code": response.status_code,
"result": result,
},
)
but I have not been able to get an environment working to be able to further isolate this.
This issue might be isolated to the UI; I have passed it through to the DB as-is and the property looks correct (numbers stored as numbers)...
Hi, @mieslep. I'm Dosu, and I'm helping the langflow team manage their backlog. I'm marking this issue as stale.
Issue Summary:
- You reported a bug where server responses with correct data types are converted to strings in the component output.
- The issue might be related to the serialization process in the
make_requestmethod usingjson.dumps(data). - You suspect the problem could be in the deserialization of the
Dataobject but haven't tested due to environment setup issues. - The issue might be isolated to the UI, as the data appears correct when passed to the database.
Next Steps:
- Please let us know if this issue is still relevant to the latest version of the langflow repository by commenting on this issue.
- If there is no further activity, the issue will be automatically closed in 7 days.
Thank you for your understanding and contribution!