Use json str, normalize keys

This commit is contained in:
shamoon
2025-09-14 20:54:13 -07:00
parent 5a8b470673
commit 1d6cdf7b1d
2 changed files with 13 additions and 5 deletions

View File

@@ -1758,6 +1758,8 @@ class PostDocumentSerializer(serializers.Serializer):
"value": value,
},
)
# Normalize keys to integers for later
return {int(k): v for k, v in custom_fields_w_values.items()}
def validate_created(self, created):
# support datetime format for created for backwards compatibility

View File

@@ -1,4 +1,5 @@
import datetime
import json
import shutil
import tempfile
import uuid
@@ -1551,7 +1552,10 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
with (Path(__file__).parent / "samples" / "simple.pdf").open("rb") as f:
response = self.client.post(
"/api/documents/post_document/",
{"document": f, "custom_fields_w_values": {"3456": "a string"}},
{
"document": f,
"custom_fields_w_values": json.dumps({"3456": "a string"}),
},
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.consume_file_mock.assert_not_called()
@@ -1571,10 +1575,12 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
"/api/documents/post_document/",
{
"document": f,
"custom_fields_w_values": {
str(cf_string.id): "a string",
str(cf_int.id): 123,
},
"custom_fields_w_values": json.dumps(
{
str(cf_string.id): "a string",
str(cf_int.id): 123,
},
),
},
)