A set[str] field of a fragment with validate_on_load=False loads the stored list as a list, not a set
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with drivine/mapper/graph_object_mapper.py and inspect _properties, _collected, and _instance; the issue describes how validate_on_load=False skips coercion. Port the listed unit and integration cases from SetFields.spec.ts and StatelessGraphObjectManager.sets.spec.ts, covering fragments, views, relationships, paths, nulls, and absent values. Done means declared set fields load as sets without changing absent or null values, and loaded sets save back as lists.
由索引模型根据 Issue 内容生成。
描述
Port of liberation-data/drivine#280.
What happens here now: a set[str] field of a fragment declared with validate_on_load=False loads the list the store holds as a list, not a set. A validated fragment is fine: Pydantic's model_validate coerces the list to the field's set.
GraphObjectMapper._properties (drivine/mapper/graph_object_mapper.py:84-114) copies each stored value as it is, and only an empty_when_absent field passes through _collected (line 111-113). fragment() then builds the instance with _instance(..., model.validate_on_load) (line 45), and _instance (line 122-123) uses model_construct when validation is off, which coerces nothing. So the same field loads as set() when the node holds nothing for it (@EmptyWhenAbsent), and as a list when it holds items. A tuple[...] field has the same gap. Relationship and path collections already go through _collected with their kind, validated or not (lines 53-62).
Checked against main (987f07f):
class U(NodeFragment, labels=["U"], validate_on_load=False):
id: Annotated[str, NodeId()]
codes: set[str] = set()
mapper.fragment(registry.fragment(U), {"props": {"id": "1", "codes": ["x", "y"]}, "labels": ["U"]}).codes
# ['x', 'y'], a list; the same class without validate_on_load=False gives {'x', 'y'}
What the fix in drivine does: the registry records which fields hold a Set (FieldMapping.sets), and the mapper turns the list a store holds for such a field into a Set, in fragments, views, the fragments and views they hold, relationship fragments and paths. A field the node holds nothing for, or holds null, is left as it is unless it has @EmptyWhenAbsent. A {} a set was held as before sets were stored as lists loads as an empty set.
Suggested fix here: have _properties pass a stored list through _collected for any field whose FieldShape is a set or tuple, so model_construct gets the declared collection too.
Tests to port: drivine's test/1.Unit/mapper/SetFields.spec.ts (a load gives a set; absent stays absent; null stays null; in a view, a nested view, a relationship fragment and a path) and test/2.Integration/manager/StatelessGraphObjectManager.sets.spec.ts (store as a list, load as a set, save the loaded set back as a list, on every store), each with validate_on_load=False.
- 主要语言
- Python
- 星标
- 1
- 派生
- 0
- 平均合并
- 1 小时 16 分钟
- 30 天内合并 PR
- 74
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
liberation-data/drivine-python 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
liberation-data/drivine-python#154 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
liberation-data/drivine-python#152 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
liberation-data/drivine-python#150 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
liberation-data/drivine-python#138 ·
维护者通常 1 天内回复
-
Cypher on SQL stores: all(), any(), none() and single() are two-valued where the predicate is null未关闭
难度 4/5 3-5 天 新手友好度 55/100
liberation-data/drivine-python#159 ·
维护者通常 1 天内回复
查看 liberation-data/drivine-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
UKGovernmentBEIS/optstop#10 ·
-
maintenance
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
pollen-robotics/reachy_mini#1508 ·
维护者通常 1 天内回复
-
[BUG] `cloud-keys.env` values retain enclosing quotes causing 401 Unauthorized, and missing utf-8 encoding crashes on Windows可能已有人在做 @divyanshu07-code 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 77/100
open-jarvis/OpenJarvis#1192 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
sylvainmetayer/homelab#851 ·
维护者通常 1 天内回复