René's URL Explorer Experiment


Title: Model serialization drops keys · Issue #105 · gleanwork/api-client-python · GitHub

Open Graph Title: Model serialization drops keys · Issue #105 · gleanwork/api-client-python

X Title: Model serialization drops keys · Issue #105 · gleanwork/api-client-python

Description: There may be an issue affecting the serialize_model methods of the Pydantic models in this library. Taking the DocumentContent model as an example, we see: class DocumentContent(BaseModel): full_text_list: Annotated[ Optional[List[str]],...

Open Graph Description: There may be an issue affecting the serialize_model methods of the Pydantic models in this library. Taking the DocumentContent model as an example, we see: class DocumentContent(BaseModel): full_te...

X Description: There may be an issue affecting the serialize_model methods of the Pydantic models in this library. Taking the DocumentContent model as an example, we see: class DocumentContent(BaseModel): full_te...

Opengraph URL: https://github.com/gleanwork/api-client-python/issues/105

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Model serialization drops keys","articleBody":"There may be an issue affecting the `serialize_model` methods of the Pydantic models in this library.\n\nTaking the [`DocumentContent`](https://github.com/gleanwork/api-client-python/blob/56b3b86fba975cd22b00cc29c592f0e01143c284/src/glean/api_client/models/documentcontent.py#L16) model as an example, we see:\n\n```py\nclass DocumentContent(BaseModel):\n    full_text_list: Annotated[\n        Optional[List[str]], pydantic.Field(alias=\"fullTextList\")\n    ] = None\n    r\"\"\"The plaintext content of the document.\"\"\"\n\n    @model_serializer(mode=\"wrap\")\n    def serialize_model(self, handler):\n        optional_fields = set([\"fullTextList\"])\n        serialized = handler(self)\n        m = {}\n\n        for n, f in type(self).model_fields.items():\n            k = f.alias or n\n            val = serialized.get(k)\n\n            if val != UNSET_SENTINEL:\n                if val is not None or k not in optional_fields:\n                    m[k] = val\n\n        return m\n```\n\nThis model uses a field alias that, when constructing the Pydantic object from an API response, will map the `fullTextList` field of the JSON object to the `full_text_list` field of the Pydantic object.\n\nHowever, the model serializer uses:\n\n```py\n...\nk = f.alias or n\nval = serialized.get(k)\n...\n```\n\nwhich means that the field alias (`fullTextList`) will be used to extract the value rather than the Pydantic field name. This results in `value` being `None` and in missing keys in the returned dictionary `m` when the field name and its alias are different.\n\nTo support this claim, please find attached a [`documents.json`](https://github.com/user-attachments/files/24693667/documents.json) file that contains an anonymized response collected from the Glean API (`/rest/api/v1/getdocuments` [endpoint](https://developers.glean.com/api/client-api/documents/getdocuments)).\n\nAnd below is a simple `debug.py` script to run alongside it:\n\n```py\nimport pathlib\n\nfrom glean.api_client import models\nfrom glean.api_client.utils.unmarshal_json_response import unmarshal_json_response\n\n\nclass DummyHttpResponse:\n    def __init__(self, text):\n        self.status_code = 200\n        self.text = text\n\n\nwith pathlib.Path(\"documents.json\").open(\"r\") as f:\n    http_res = DummyHttpResponse(\n        text=f.read(),\n    )\n\n\ndocuments_response = unmarshal_json_response(models.GetDocumentsResponse, http_res)\n\n\nassert isinstance(documents_response, models.GetDocumentsResponse)\nassert documents_response.documents is not None\nassert isinstance(\n    documents_response.documents[\"https://company.com/Test\"].content,\n    models.DocumentContent,\n)\nassert (\n    documents_response.documents[\"https://company.com/Test\"].content.full_text_list[0]\n    == \"This is a test document.\"\n)\n\nserialized_document_response = documents_response.model_dump()\n\nassert isinstance(serialized_document_response, dict)\nassert serialized_document_response[\"documents\"] is not None\n\n# Here's the problem: no `full_text_list` or `fullTextList` in the serialized response!\nassert (\n    len(serialized_document_response[\"documents\"][\"https://company.com/Test\"][\"content\"])\n    \u003e 0\n)\n```\n\nRunning it yields:\n\n```shell\n$ ls    \ndebug.py  documents.json\n\n$ python debug.py\nTraceback (most recent call last):\n  File \"/workspace/app/debug/debug.py\", line 40, in \u003cmodule\u003e\n    len(serialized_document_response[\"documents\"][\"https://company.com/Test\"][\"content\"])\n    \u003e 0\nAssertionError\n```\n\nNote that I'm using:\n\n```\npydantic_core==2.41.5\npydantic==2.12.5\nglean-api-client==0.11.27\n```","author":{"url":"https://github.com/lucas-bremond","@type":"Person","name":"lucas-bremond"},"datePublished":"2026-01-18T05:36:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/105/api-client-python/issues/105"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b2703d0c-3332-fbcd-2f67-c4e0a388f4cc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id947C:AB4C6:62A095F:86023BF:697849C7
html-safe-nonced71d33696c4bcce3042b2080b234a3d28974679c315d5488e0f6aa311642cbad
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDdDOkFCNEM2OjYyQTA5NUY6ODYwMjNCRjo2OTc4NDlDNyIsInZpc2l0b3JfaWQiOiI2NDg2Nzg3NDYzNjY5MzY5Mjg3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac125d0f51c877a185511e649c97f097a6ed8ff43e61bd0ce27ea92c7cc69587c6
hovercard-subject-tagissue:3826371445
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/105/issue_layout
twitter:imagehttps://opengraph.githubassets.com/61ad460b6fb3c16fa865926fa2c1cd06a86cf6bdb6906d28add3ad666be2bece/gleanwork/api-client-python/issues/105
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/61ad460b6fb3c16fa865926fa2c1cd06a86cf6bdb6906d28add3ad666be2bece/gleanwork/api-client-python/issues/105
og:image:altThere may be an issue affecting the serialize_model methods of the Pydantic models in this library. Taking the DocumentContent model as an example, we see: class DocumentContent(BaseModel): full_te...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelucas-bremond
hostnamegithub.com
expected-hostnamegithub.com
None2981c597c945c1d90ac6fa355ce7929b2f413dfe7872ca5c435ee53a24a1de50
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
release520b65a872113b919c1bbdb03834a50af15859fd
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/105#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%2F105
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%2F105
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/105
Reloadhttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/105
Reloadhttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/105
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 5 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/105
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/gleanwork/api-client-python/issues/105
Model serialization drops keyshttps://patch-diff.githubusercontent.com/gleanwork/api-client-python/issues/105#top
https://github.com/lucas-bremond
https://github.com/lucas-bremond
lucas-bremondhttps://github.com/lucas-bremond
on Jan 18, 2026https://github.com/gleanwork/api-client-python/issues/105#issue-3826371445
DocumentContenthttps://github.com/gleanwork/api-client-python/blob/56b3b86fba975cd22b00cc29c592f0e01143c284/src/glean/api_client/models/documentcontent.py#L16
documents.jsonhttps://github.com/user-attachments/files/24693667/documents.json
endpointhttps://developers.glean.com/api/client-api/documents/getdocuments
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.