kevinjqliu opened a new pull request, #3411:
URL: https://github.com/apache/iceberg-python/pull/3411

   ## Problem
   
   `PartitionField` and `SortField` accept the v3 `source-ids` list (added in 
[#1554](https://github.com/apache/iceberg-python/pull/1554)) and map it to the 
legacy singular `source-id`. Both validators try to reject an empty list:
   
   ```python
   if "source-id" not in data and (source_ids := data["source-ids"]):
       if isinstance(source_ids, list):
           if len(source_ids) == 0:
               raise ValueError("Empty source-ids is not allowed")
           ...
           data["source-id"] = source_ids[0]
   ```
   
   The walrus uses truthiness, and `[]` is falsy — so the `len(source_ids) == 
0` branch is unreachable. Passing `{"source-ids": []}` silently skips the 
mapping, and Pydantic then reports a generic "field required" error instead of 
the intended message. A missing `source-ids` key also raises `KeyError` instead 
of being handled cleanly.
   
   ## Fix
   
   Replace the walrus with an explicit key check in both validators:
   
   ```python
   if "source-id" not in data and "source-ids" in data:
       source_ids = data["source-ids"]
       ...
   ```
   
   This makes the empty-list validation reachable and avoids the `KeyError`.
   
   ## Tests
   
   Added regression tests that deserialize `{"source-ids": []}` and assert 
`ValueError("Empty source-ids is not allowed")` is raised, for both 
`PartitionField` and `SortField`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to