Django VectorField and HalfVectorField to_python fail on a NumPy array since 0.5.0
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 78/100
研究方向
從 Django 整合中的 VectorField.to_python 和 HalfVectorField.to_python 開始,接著閱讀 tests/test_django.py 中的 test_clean,了解欄位清理是如何涵蓋的。為 NumPy 陣列新增測試,並檢查兩個欄位的 field.clean(value, None) 都能接受這些陣列,與現有的列表、字串和向量案例一致。
由索引模型根據 Issue 內容生成。
描述
Since fdd559a ("Simplified code", shipped in 0.5.0), VectorField.to_python and HalfVectorField.to_python pass anything that is not a list to _from_db, which only knows None, the vector class and str. A NumPy array reaches _from_text and fails on .split, so full_clean() breaks on a model that save() accepts, because get_prep_value still goes through Vector(value).
$ python -I pgv_repro.py # master 1cbee1a, Django 6.1.2, NumPy 2.5.4, Python 3.12.3
VectorField list -> [1.0, 2.0, 3.0]
VectorField str -> [1.0, 2.0, 3.0]
VectorField Vector -> [1.0, 2.0, 3.0]
VectorField ndarray -> AttributeError 'numpy.ndarray' object has no attribute 'split'
HalfVectorField ndarray -> AttributeError 'numpy.ndarray' object has no attribute 'split'
$ PYTHONPATH=<tree at fdd559a^> python pgv_repro.py
VectorField ndarray -> [1.0, 2.0, 3.0]
HalfVectorField ndarray -> [1.0, 2.0, 3.0]
The script calls field.clean(value, None) on each input, which is the path Model.full_clean() takes. test_clean in tests/test_django.py only passes lists, which is why the suite stayed green.
_to_db already builds the class from anything else, so I'd add that one step to to_python and keep the _from_db call (HalfVector the same way in halfvec.py):
if isinstance(value, list):
return value
if value is not None and not isinstance(value, (str, Vector)):
value = Vector(value)
return Vector._from_db(value)
$ PYTHONPATH=<1cbee1a + that change, both fields> python pgv_repro.py # Python 3.12.6
VectorField list -> [1.0, 2.0, 3.0]
VectorField str -> [1.0, 2.0, 3.0]
VectorField Vector -> [1.0, 2.0, 3.0]
VectorField ndarray -> [1.0, 2.0, 3.0]
HalfVectorField list -> [1.0, 2.0, 3.0]
HalfVectorField str -> [1.0, 2.0, 3.0]
HalfVectorField HalfVector -> [1.0, 2.0, 3.0]
HalfVectorField ndarray -> [1.0, 2.0, 3.0]
@ankane I can add the NumPy case to test_clean in the same change, if you want it as a pull request.
- 主要語言
- Python
- 星號
- 1.5k
- 分支
- 97
- 平均合併
- 13 分鐘
- 30 天內合併 PR
- 1
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
相似的 Issue
-
[Bug]: Streamed /v1/chat/completions sends unredacted agent error text (keys) in the final chunk可能已有人在做 @rodricksz4h5 今天認領。 未關閉area/streaming comp/gateway P2 type/security
難度 2/5 1-3 小時 新手友好度 78/100
NousResearch/hermes-agent#138245 ·
維護者通常 1 天內回覆
-
[oblt-aw][autodoc] Update user onboarding guide for mandatory trigger CODEOWNERS step可能已有人在做 @github-actions 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 1 天內回覆
-
correction metadata
難度 2/5 1 小時以內 新手友好度 68/100
acl-org/acl-anthology#10378 · 1 則留言 ·
維護者通常 1 天內回覆
-
cloudtrail_multi_region_enabled_logging_management_events fails when the advanced event selector has a custom name可能已有人在做 @12YYCCYY16 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
prowler-cloud/prowler#13033 ·
維護者通常 1 天內回覆
-
enhancement
難度 1/5 1-3 小時 新手友好度 88/100
graygarbage/HermesKey#23 ·