Title: `AnswerLikes.likedBy` field validation error: Pydantic expects list but API returns null · Issue #47 · gleanwork/api-client-python · GitHub
Open Graph Title: `AnswerLikes.likedBy` field validation error: Pydantic expects list but API returns null · Issue #47 · gleanwork/api-client-python
X Title: `AnswerLikes.likedBy` field validation error: Pydantic expects list but API returns null · Issue #47 · gleanwork/api-client-python
Description: generated by Claude Sonnet 4 Environment Glean Python SDK Version: glean-api-client==0.6.5 (Generated by Speakeasy) Python Version: 3.10.14 Pydantic Version: 2.x Operating System: macOS Date Reported: June 14, 2025 Summary The Glean Pyth...
Open Graph Description: generated by Claude Sonnet 4 Environment Glean Python SDK Version: glean-api-client==0.6.5 (Generated by Speakeasy) Python Version: 3.10.14 Pydantic Version: 2.x Operating System: macOS Date Report...
X Description: generated by Claude Sonnet 4 Environment Glean Python SDK Version: glean-api-client==0.6.5 (Generated by Speakeasy) Python Version: 3.10.14 Pydantic Version: 2.x Operating System: macOS Date Report...
Opengraph URL: https://github.com/gleanwork/api-client-python/issues/47
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`AnswerLikes.likedBy` field validation error: Pydantic expects list but API returns null","articleBody":"*generated by Claude Sonnet 4*\n\n## Environment\n- **Glean Python SDK Version**: glean-api-client==0.6.5 (Generated by Speakeasy)\n- **Python Version**: 3.10.14\n- **Pydantic Version**: 2.x\n- **Operating System**: macOS\n- **Date Reported**: June 14, 2025\n\n## Summary\nThe Glean Python SDK fails to parse chat API responses when answers have no likes, causing a Pydantic validation error. The `AnswerLikes.liked_by` field is defined as a required `List[AnswerLike]` but the API returns `null` when there are no likes.\n\n## Error Details\n\n### Full Error Message\n```\n1 validation error for Unmarshaller\nbody.messages.2.fragments.1.structuredResults.0.answer.likes.likedBy\n Input should be a valid list [type=list_type, input_value=None, input_type=NoneType]\n For further information visit https://errors.pydantic.dev/2.11/v/list_type\n```\n\n### Stack Trace\n```python\nFile \"\u003cshorten\u003e/lib/python3.10/site-packages/glean/api_client/client_chat.py\", line 139, in create\n return utils.unmarshal_json(http_res.text, models.ChatResponse)\nFile \"\u003cshorten\u003e/lib/python3.10/site-packages/glean/api_client/utils/serializers.py\", line 140, in unmarshal_json\n return unmarshal(from_json(raw), typ)\nFile \"\u003cshorten\u003e/lib/python3.10/site-packages/glean/api_client/utils/serializers.py\", line 150, in unmarshal\n m = unmarshaller(body=val)\nFile \"\u003cshorten\u003e/lib/python3.10/site-packages/pydantic/main.py\", line 253, in __init__\n validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)\npydantic_core._pydantic_core.ValidationError: 1 validation error for Unmarshaller\n```\n\n## Reproduction Steps\n1. Use the Glean Python SDK to make a chat API call\n2. Ask a question that returns answers with zero likes\n3. The SDK fails to parse the response due to `likedBy: null` in the JSON\n\n### Minimal Reproduction Code\n```python\nimport os\nfrom glean.api_client import Glean, models\n\ndef reproduce_bug():\n with Glean(\n api_token=os.getenv('GLEAN_API_KEY'),\n instance='\u003cinstance\u003e',\n ) as client:\n res = client.client.chat.create(messages=[\n {\n \"fragments\": [\n models.ChatMessageFragment(\n text=\"What is invocation context in LinkedIn production system?\",\n ),\n ],\n },\n ], timeout_millis=30000)\n return res\n\n# This will fail with the validation error\nreproduce_bug()\n```\n\n## Root Cause Analysis\n\n### Problem Location\nFile: `glean/api_client/models/answerlikes.py`\nLine: ~22\n\n### Current (Incorrect) Definition\n```python\nclass AnswerLikes(BaseModel):\n liked_by: Annotated[List[\"AnswerLike\"], pydantic.Field(alias=\"likedBy\")]\n # ... other fields\n```\n\n### API Behavior vs Schema Mismatch\n- **Schema Expectation**: `likedBy` is a required array of `AnswerLike` objects\n- **Actual API Response**: `likedBy` can be `null` when no likes exist\n- **Pydantic Validation**: Fails because `null` is not a valid `List`\n\n## Proposed Solutions\n\n### Option 1: Make Field Optional (Recommended)\n```python\nclass AnswerLikes(BaseModel):\n liked_by: Annotated[Optional[List[\"AnswerLike\"]], pydantic.Field(alias=\"likedBy\", default_factory=list)]\n # ... other fields\n```\n\n### Option 2: Update API to Return Empty Array\nChange the API to return `\"likedBy\": []` instead of `\"likedBy\": null`\n\n### Option 3: Update OpenAPI Specification\nIf this is generated from an OpenAPI spec, update the specification to mark `likedBy` as nullable/optional.\n\n## Temporary Workaround Applied\nWe temporarily modified the generated SDK file with Option 1 fix:\n\n```python\n# Added Optional import\nfrom typing import List, TYPE_CHECKING, Optional\n\n# Modified field definition\nliked_by: Annotated[Optional[List[\"AnswerLike\"]], pydantic.Field(alias=\"likedBy\", default_factory=list)]\n```\n\nThis workaround works but will be overwritten when the SDK is regenerated.\n\n## Impact\n- **Severity**: High - Breaks basic chat API functionality\n- **Frequency**: Common - Occurs whenever answers have no likes\n- **Workaround Available**: Yes, but requires manual SDK modification\n\n## Additional Context\n- The error occurs specifically in chat responses containing answer results\n- The `AnswerLikesTypedDict` in the same file also defines `liked_by` as required, suggesting this might be a specification issue\n- This affects any application using the Glean chat API that encounters answers with zero likes\n\n## SDK Generation Details\n- Generated by: Speakeasy (https://speakeasy.com)\n- File header indicates: \"DO NOT EDIT\" - confirming this is auto-generated\n- Suggests the fix should be in the source specification or generation logic\n\n## Request\nPlease fix this by either:\n1. Updating the OpenAPI specification to mark `likedBy` as optional/nullable\n2. Updating the API implementation to return empty arrays instead of null\n3. Updating the SDK generation logic to handle nullable arrays properly\n\nThis issue prevents normal usage of the Glean chat API in production environments.\n","author":{"url":"https://github.com/ddu4","@type":"Person","name":"ddu4"},"datePublished":"2025-06-15T05:20:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/47/api-client-python/issues/47"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2373d799-56a4-37de-4a74-b6a9732f52ed |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE2C:F9F81:1C8C964:261E3D7:697D3186 |
| html-safe-nonce | 2c0262b906479b1bc6f4f3b008477e019c32eb9010851f3c8b3247c8e01a686b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTJDOkY5RjgxOjFDOEM5NjQ6MjYxRTNENzo2OTdEMzE4NiIsInZpc2l0b3JfaWQiOiI1NjY2NjU2MTc0MjMzOTU2NzQyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d5c8e7f26767317be6ba2ac87ac2c041f12ccd04c10e9b3ce8dbf51cdc330349 |
| hovercard-subject-tag | issue:3147115462 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gleanwork/api-client-python/47/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1b03002b194a7f144aec9feaf9ee2f6ce002a9db0a707fe322f0eebd03648a0b/gleanwork/api-client-python/issues/47 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1b03002b194a7f144aec9feaf9ee2f6ce002a9db0a707fe322f0eebd03648a0b/gleanwork/api-client-python/issues/47 |
| og:image:alt | generated by Claude Sonnet 4 Environment Glean Python SDK Version: glean-api-client==0.6.5 (Generated by Speakeasy) Python Version: 3.10.14 Pydantic Version: 2.x Operating System: macOS Date Report... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ddu4 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 947d30920225f8abb17692477afd5992252045b901780d1bc8fa47c03b5fde64 |
| turbo-cache-control | no-preview |
| go-import | github.com/gleanwork/api-client-python git https://github.com/gleanwork/api-client-python.git |
| octolytics-dimension-user_id | 100331376 |
| octolytics-dimension-user_login | gleanwork |
| octolytics-dimension-repository_id | 971642383 |
| octolytics-dimension-repository_nwo | gleanwork/api-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 971642383 |
| octolytics-dimension-repository_network_root_nwo | gleanwork/api-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 92fcc0e25bb4da7fe9a458840cb7f3cafa272eb8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width