From 094397b503141710f6a9c11583595869b94b8861 Mon Sep 17 00:00:00 2001 From: Zach Leventer Date: Thu, 23 Apr 2026 21:10:05 -0400 Subject: [PATCH] Fix #62: prevent TypeError when elements is missing from batch create response When the JSON response lacks an "elements" key, json_data.get() returns None, which cannot be iterated. Default to an empty list instead, matching the pattern already used by BatchFinderResponseFormatter. Co-Authored-By: Claude Opus 4.6 (1M context) --- linkedin_api/clients/restli/response_formatter.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/linkedin_api/clients/restli/response_formatter.py b/linkedin_api/clients/restli/response_formatter.py index 0f7da7b..a6c0c52 100644 --- a/linkedin_api/clients/restli/response_formatter.py +++ b/linkedin_api/clients/restli/response_formatter.py @@ -140,9 +140,11 @@ class BatchCreateResponseFormatter(BaseResponseFormatter[BatchCreateResponse]): def format_response(cls, response: Response) -> BatchCreateResponse: json_data = response.json() elements = json_data.get("elements", None) - batch_create_results = [ - cls.format_batch_create_result(result) for result in elements - ] + batch_create_results = ( + [cls.format_batch_create_result(result) for result in elements] + if elements + else [] + ) return BatchCreateResponse( status_code=response.status_code,