Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng
#129 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #204 của @jasperblues — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
67/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
1
Fork
0
Merge trung bình
1 giờ 13 phút
Pull request đã merge (30 ngày)
109

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của liberation-data/drivine-python

Tất cả issue của liberation-data/drivine-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.