gleanwork / gleanwork/api-client-python

Value model in AdditionalFieldDefinition is an empty class, thus silently drops all data

未關閉
#133 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Python
星號
20
分支
10
平均合併
1 天 6 小時
30 天內合併 PR
17

描述

The Value class in additionalfielddefinition.py is defined as an empty Pydantic BaseModel with no fields:

class Value(BaseModel):
  r"""Either a string or HypertextField. When OpenAPI Generator supports oneOf, we can semantically enforce this in the docs."""

Because the SDK's BaseModel uses the default Pydantic extra = 'ignore' behavior, any data passed to Value(...) is silently discarded. This means the value field on AdditionalFieldDefinition, which is typed as Optional[List[Value]], cannot actually carry any data.
Impact

This affects any consumer using AdditionalFieldDefinition through either:

  • EmployeeInfoDefinition.additional_fields
  • TeamInfoDefinition.additional_fields

When constructing an AdditionalFieldDefinition with values, the data in the value list is lost:

from glean.api_client.models.additionalfielddefinition import AdditionalFieldDefinition, Value
field = AdditionalFieldDefinition(
  key="languages",
  value=[Value(anchor="English"), Value(anchor="Spanish")]
)
print(field.model_dump())
# {'key': 'languages', 'value': [{}, {}]}
#                                 ^^   ^^  all data silently dropped

The same applies to HypertextField-style values:

Value(anchor="Glean", hyperlink="https://glean.com")
# Value()  — both anchor and hyperlink are silently ignored

This is the associated public docs page: https://developers.glean.com/api/indexing-api/bulk-index-employees. Note that even when passing in data to Value() as a dict, the whole dict object is ignored:

from glean.api_client.models.additionalfielddefinition import AdditionalFieldDefinition

raw = {"key": "username", "value": [{"username": "testuser"}]}
field = AdditionalFieldDefinition(**raw)
dumped = field.model_dump()
print(dumped)
# {'key': 'username', 'value': [{}]}

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先在 glean/api_client/models/additionalfielddefinition.py 中檢查空的 Value 模型,以及 AdditionalFieldDefinition 如何建構其 value 清單。使用 anchor、hyperlink 和 dictionary 輸入重現文件中的範例,接著確認 model_dump() 會保留提供的資料,而不是產生空物件。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
api
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。