cloudflare / cloudflare/cloudflare-python

KV Value Update handles Data wrongly

未關閉
#2,519 4 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
509
分支
150
平均合併
3 小時 15 分鐘
30 天內合併 PR
1

描述

### Confirm this is a Python library issue and not an underlying Cloudflare API issue.

- [x] This is an issue with the Python library

### Describe the bug

When trying to set a value in the KV Store `metadata` needs to be provided, but gets merged into the `value` and no meta data gets set.

```
In [29]: response = client.kv.namespaces.values.update(key_name="test", value="MY VALUE", metadata="{}", **kv.params)

In [30]: print(client.kv.namespaces.values.get(key_name="test", **kv.params).text())
{"metadata":"{}","value":"MY VALUE"}

In [31]: print(client.kv.namespaces.metadata.get(key_name="test", **kv.params) is None)
True
```
The problem seems to be caused from the whole body of the request being used as the actual value. The behaviour seems to be correct when manually specifying the request's content tye as `multipart/form-data`:

```
In [38]: response = client.kv.namespaces.values.update(key_name="test", value="MY VALUE", metadata="{}", **kv.params, extra_headers={"Content-Type": "multipart/form-data"})

In [39]: print(client.kv.namespaces.values.get(key_name="test", **kv.params).text())
MY VALUE

In [40]: print(client.kv.namespaces.metadata.get(key_name="test", **kv.params))
{}
```
This should probably be the default behaviour as it shouldn't be necessary to explicitly override the content type. On the other hand `metadata` should not be required in which case the whole body could be set as `value`

### To Reproduce

1. Call `values.update()` with a `value` and `metadata`. Both are set as the actual value.
2. `metadata.get()` doesn't return any metadata.
3. Metadata is returned with the value upon calling `values.get()`.

### Code snippets

```Python

```

### OS

Every OS

### Python version

3.12

### Library version

v4.0.0

貢獻指南

開啟貢獻指南

研究方向

從 values.update() 和 metadata.get() 入口點開始,檢查 value、metadata 和 Content-Type 的傳送方式。使用兩個欄位重現請求,然後為預期的 metadata 行為新增回歸測試。當 metadata 分開儲存,且 values.get() 不再將其作為 value 的一部分回傳時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
api, backend
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。