Skip to content

KV Value Update handles Data wrongly #2519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
bvallant opened this issue Mar 12, 2025 · 2 comments
Open
1 task done

KV Value Update handles Data wrongly #2519

bvallant opened this issue Mar 12, 2025 · 2 comments

Comments

@bvallant
Copy link

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

@Levana13
Copy link

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

product_template.csv

@Levana13
Copy link

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))
{}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants