Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

A set[str] field of a fragment with validate_on_load=False loads the stored list as a list, not a set

未关闭
#129 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
1-2 天
新手友好度
67/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

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 内容生成。

描述

bug

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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

liberation-data/drivine-python 的其他 Issue

查看 liberation-data/drivine-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。