René's URL Explorer Experiment


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

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2373d799-56a4-37de-4a74-b6a9732f52ed
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAE2C:F9F81:1C8C964:261E3D7:697D3186
html-safe-nonce2c0262b906479b1bc6f4f3b008477e019c32eb9010851f3c8b3247c8e01a686b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTJDOkY5RjgxOjFDOEM5NjQ6MjYxRTNENzo2OTdEMzE4NiIsInZpc2l0b3JfaWQiOiI1NjY2NjU2MTc0MjMzOTU2NzQyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd5c8e7f26767317be6ba2ac87ac2c041f12ccd04c10e9b3ce8dbf51cdc330349
hovercard-subject-tagissue:3147115462
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gleanwork/api-client-python/47/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1b03002b194a7f144aec9feaf9ee2f6ce002a9db0a707fe322f0eebd03648a0b/gleanwork/api-client-python/issues/47
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1b03002b194a7f144aec9feaf9ee2f6ce002a9db0a707fe322f0eebd03648a0b/gleanwork/api-client-python/issues/47
og:image:altgenerated 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameddu4
hostnamegithub.com
expected-hostnamegithub.com
None947d30920225f8abb17692477afd5992252045b901780d1bc8fa47c03b5fde64
turbo-cache-controlno-preview
go-importgithub.com/gleanwork/api-client-python git https://github.com/gleanwork/api-client-python.git
octolytics-dimension-user_id100331376
octolytics-dimension-user_logingleanwork
octolytics-dimension-repository_id971642383
octolytics-dimension-repository_nwogleanwork/api-client-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id971642383
octolytics-dimension-repository_network_root_nwogleanwork/api-client-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release92fcc0e25bb4da7fe9a458840cb7f3cafa272eb8
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/47#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgleanwork%2Fapi-client-python%2Fissues%2F47
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgleanwork%2Fapi-client-python%2Fissues%2F47
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=gleanwork%2Fapi-client-python
Reloadhttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/47
Reloadhttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/47
Reloadhttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/47
gleanwork https://patch-diff.githubusercontent.com/gleanwork
api-client-pythonhttps://patch-diff.githubusercontent.com/gleanwork/api-client-python
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fgleanwork%2Fapi-client-python
Fork 6 https://patch-diff.githubusercontent.com/login?return_to=%2Fgleanwork%2Fapi-client-python
Star 14 https://patch-diff.githubusercontent.com/login?return_to=%2Fgleanwork%2Fapi-client-python
Code https://patch-diff.githubusercontent.com/gleanwork/api-client-python
Issues 4 https://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues
Pull requests 1 https://patch-diff.githubusercontent.com/gleanwork/api-client-python/pulls
Actions https://patch-diff.githubusercontent.com/gleanwork/api-client-python/actions
Projects 0 https://patch-diff.githubusercontent.com/gleanwork/api-client-python/projects
Security 0 https://patch-diff.githubusercontent.com/gleanwork/api-client-python/security
Insights https://patch-diff.githubusercontent.com/gleanwork/api-client-python/pulse
Code https://patch-diff.githubusercontent.com/gleanwork/api-client-python
Issues https://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues
Pull requests https://patch-diff.githubusercontent.com/gleanwork/api-client-python/pulls
Actions https://patch-diff.githubusercontent.com/gleanwork/api-client-python/actions
Projects https://patch-diff.githubusercontent.com/gleanwork/api-client-python/projects
Security https://patch-diff.githubusercontent.com/gleanwork/api-client-python/security
Insights https://patch-diff.githubusercontent.com/gleanwork/api-client-python/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/gleanwork/api-client-python/issues/47
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/gleanwork/api-client-python/issues/47
AnswerLikes.likedBy field validation error: Pydantic expects list but API returns nullhttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/47#top
https://patch-diff.githubusercontent.com/rwjblue-glean
https://github.com/ddu4
https://github.com/ddu4
ddu4https://github.com/ddu4
on Jun 15, 2025https://github.com/gleanwork/api-client-python/issues/47#issue-3147115462
https://speakeasy.comhttps://speakeasy.com
rwjblue-gleanhttps://patch-diff.githubusercontent.com/rwjblue-glean
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.