Derived ids change with the Python or Node Unicode version

Đang mở
#367 2 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

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
backend, databases

Hướng nghiên cứu

Read src/selfgraph/ids.py, src/selfgraph/retrieval.py, typescript/src/ids.ts, and typescript/src/internal/casefold.ts, then inspect the conformance suite. The issue proposes pinning letter and digit classes plus lowercase and casefold tables to one Unicode version shared by both SDKs. Done means derived IDs, relation types, and retrieval tokens no longer vary with Python or Node Unicode versions, with conformance coverage for the reported cases.

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

Mô tả

approved-for-pr area: parity area: write bug effort: M P2

docs/resources.md says combining marks come "from one fixed list, the marks of Unicode 15.0, so an id does not depend on the Python or Node version." Only the marks are pinned. Letters, digits, and case still come from the runtime: \w and str.lower() in Python, \p{L}/\p{N} and toLowerCase() in TypeScript. A character the runtime does not know yet is treated as punctuation and dropped from the id. So the same name derives a different id depending on the Python minor version, and Python and Node disagree whenever their Unicode versions differ.

Tested at 5a277c9 (current main), using the ids.py from that commit under each interpreter, and the TypeScript entityId from the same commit on Node 26.12.

Reproduce
from selfgraph import entity_id

for name in ["王\U0002EBF0", "王\U0002EBF1", "王\U000323B0", "Таня \u1C89а"]:
    print(ascii(entity_id("Person", name)))

The first two names use CJK Extension I ideographs (Unicode 15.1), the third an Extension J ideograph (Unicode 17.0), and the fourth Cyrillic capital TJE (Unicode 16.0).

runtime Unicode 王 + U+2EBF0 王 + U+2EBF1 王 + U+323B0 Таня + U+1C89 а
Python 3.11 14.0 person:王 person:王 person:王 person:таня-а
Python 3.12 15.0 person:王 person:王 person:王 person:таня-а
Python 3.13 15.1 person:王𮯰 person:王𮯱 person:王 person:таня-а
Python 3.14 16.0 person:王𮯰 person:王𮯱 person:王 person:таня-ᲊа
Python 3.15 17.0 person:王𮯰 person:王𮯱 person:王𲎰 person:таня-ᲊа
Node 26 (ICU 78) 17.0 person:王𮯰 person:王𮯱 person:王𲎰 person:таня-ᲊа

Two things go wrong:

  • On an older runtime, different names merge. On Python 3.12, 王𮯰 and 王𮯱 are one entity, person:王, and so is a plain 王.
  • Upgrading Python changes ids. A graph built on Python 3.12 holds person:王. After moving to 3.13, inserting the same name derives person:王𮯰, which no longer matches the stored entity, so a duplicate appears and lookups by the derived id miss the old one. Relation ids derived from those entity ids change with them.

Scanning every code point with entity_id("Person", "Ann " + c + "x"), the number that derive a different id between consecutive Python versions is:

upgrade code points
3.10 to 3.11 525
3.11 to 3.12 4,388
3.12 to 3.13 622
3.13 to 3.14 4,382
3.14 to 3.15 4,657

That is 14,574 between 3.10 and 3.15. normalize_rel_type and the retrieval tokens are built from the same classes and case mappings, so they shift with the runtime too.

The two SDKs also disagree today on the same machine. Python 3.14 (Unicode 16.0) and Node 26 (Unicode 17.0) derive different entity_id, normalize_rel_type, and retrieval tokens for 4,657 code points. That breaks the byte-for-byte id agreement between the SDKs, and the conformance suite does not catch it.

TypeScript is also inconsistent with itself. casefold in typescript/src/internal/casefold.ts is pinned to the Unicode 15.0 tables, while entityId uses the runtime's toLowerCase. On Node 26, entityId("Person", "Ɤama") gives person:ɤama (U+A7CB, Unicode 16.0, lowercased by ICU), but tokenList("Ɤama") gives ["Ɤama"], so a query for "ɤama" does not seed it. Python 3.14 folds both.

Cause
  • Python: _PUNCT and _NON_IDENT (src/selfgraph/ids.py:208-209) use \w, and slug and _canonical_name use str.lower() (src/selfgraph/ids.py:309, :311). Both follow unicodedata.unidata_version, which is 13.0 on Python 3.10 and 17.0 on 3.15. Retrieval's _fold (src/selfgraph/retrieval.py:161) uses str.casefold(), which follows it too.
  • TypeScript: PUNCT and NON_IDENT (typescript/src/ids.ts:27-28) use PY_WORD_CLASS = "\p{L}\p{N}_" (typescript/src/internal/py.ts:6), and slug, canonicalName, and normalizeRelType use toLowerCase()/toUpperCase() (typescript/src/ids.ts:126, :131, :202). All of these follow the ICU bundled with Node.

MARK_CLASS and the TypeScript casefold table are pinned to Unicode 15.0. The letter and digit classes and the case mappings are not.

Pinning those too would make ids independent of the runtime, in line with the docs: a fixed letter/digit class (like MARK_CLASS) and fixed lowercase and casefold tables from one Unicode version, shared by both SDKs. Changing the pinned version later would then be an explicit, migrated change rather than a side effect of upgrading Python or Node.

Related: #312 and #337 are other cases where case mapping in the id and token code produces keys that do not match.

Ngôn ngữ chính
TypeScript
Star
173
Fork
58
Merge trung bình
6 giờ
Pull request đã merge (30 ngày)
120

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

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 hydra-db/selfgraph

Tất cả issue của hydra-db/selfgraph

Issue tương tự

Thêm issue về TypeScript

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.