fix(api): validate immutable document fields when value is zero (#16309)

This commit is contained in:
Harsh Kashyap
2026-06-25 16:59:12 +05:30
committed by GitHub
parent 66d86154ab
commit 8d3c3f868c
2 changed files with 56 additions and 3 deletions

View File

@@ -1041,13 +1041,13 @@ def validate_immutable_fields(update_doc_req: UpdateDocumentReq, doc):
A tuple of (error_message, error_code) if validation fails,
or (None, None) if validation passes.
"""
if update_doc_req.chunk_count and update_doc_req.chunk_count != int(getattr(doc, "chunk_num", -1)):
if update_doc_req.chunk_count is not None and update_doc_req.chunk_count != int(getattr(doc, "chunk_num", -1)):
return "Can't change `chunk_count`.", RetCode.DATA_ERROR
if update_doc_req.token_count and update_doc_req.token_count != int(getattr(doc, "token_num", -1)):
if update_doc_req.token_count is not None and update_doc_req.token_count != int(getattr(doc, "token_num", -1)):
return "Can't change `token_count`.", RetCode.DATA_ERROR
if update_doc_req.progress:
if update_doc_req.progress is not None:
progress_from_db = float(getattr(doc, "progress", -1.0))
# should not use "==" to compare two float values
if not math.isclose(update_doc_req.progress, progress_from_db):