infiniflow / infiniflow/infinity

[Bug]: HTTP SDK fusion(match_tensor) mutates the caller's fusion_params dict (KeyError on reuse)

Open Beginner friendly
#3,475 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
4.7k
Forks
445
Avg merge
2d 2h
Merged PRs (30d)
7

Description

## Problem

`fusion(method="match_tensor", fusion_params=...)` **consumes** the dict the caller passes in:

```python
params = {"field": "t", "query_tensor": [[1.0, 0.0]], "element_type": "float"}
table.output(["c1"]).match_text("body", "x", 4).fusion("match_tensor", 2, params)
print(params) # {} - the caller's dict has been gutted
table.output(["c1"]).match_text("body", "x", 4).fusion("match_tensor", 2, params)
# KeyError: 'field'
```

Any code that keeps a params dict around - a loop over queries, a shared config, a retry after a transient error - crashes on the second use.

## Root cause

`python/infinity_sdk/infinity/infinity_http.py`, `table_http_result.fusion()`:

```python
tmp_new_params = {"field": fusion_params["field"], ...}
fusion_params.pop("field") # mutates the caller's dict
fusion_params.pop("query_tensor")
fusion_params.pop("element_type")
tmp_new_params.update(fusion_params)
```

The `pop()` calls exist to merge "the remaining keys" into the request params, but they mutate the caller's object as a side effect. The embedded SDK reads the same keys without popping, so it does not have this problem.

## Fix

Build the merged params with a dict comprehension that excludes the three handled keys, leaving the caller's dict untouched. The request payload is identical to before.

## Testing

- Reproduced on current main (eca7266): after one `fusion("match_tensor", ...)` call the caller's dict is empty and the second call raises `KeyError: 'field'`. After the fix the dict is unchanged and both calls build the same request params as before.
- Added regression test `test_fusion_match_tensor_reused_params` in `python/test_pysdk/test_knn.py` (reuses one params dict across two queries).
- Full pysdk suite not run locally; it needs a running server. The change is confined to the HTTP client's fusion payload builder.

Contributor guide

Open the contributing guide

Research direction

Start in python/infinity_sdk/infinity/infinity_http.py at table_http_result.fusion(), then inspect test_fusion_match_tensor_reused_params in python/test_pysdk/test_knn.py. Verify that reusing one match_tensor params dictionary across two queries leaves the caller's dictionary unchanged and preserves the existing request payload; run the focused test, noting the full suite requires a running server.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
91/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.