KV Value Update handles Data wrongly

オープン
#2,519 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
api, backend

調査の方向性

エントリポイント values.update() と metadata.get() から始め、value、metadata、Content-Type がどのように送信されるかを調べます。両方のフィールドを含むリクエストを再現し、その後、意図した metadata の動作に対するリグレッションテストを追加します。metadata が分離して保存され、values.get() が value の一部として返さなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Confirm this is a Python library issue and not an underlying Cloudflare API issue.
  • 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

OS

Every OS

Python version

3.12

Library version

v4.0.0

主要言語
Python
スター
509
フォーク
150
平均マージ
3時間 15分
マージ済み PR(30日)
1

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cloudflare/cloudflare-python のほかの issue

cloudflare/cloudflare-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。