Union does not check lineage: unrelated tables whose keys share a name are merged
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
调研方向
从 Union.create 开始(位于 src/datajoint/expression.py 中),并将其与调用 assert_join_compatibility 的 join 路径进行比较,该调用位于 src/datajoint/condition.py 中。复现该代码片段,然后让 union 在合并同名项之前执行相同的 lineage 检查,并将仅键、次级属性和同源对照用例添加到 tests/integration/test_semantic_matching.py。完成意味着 lineage 不匹配的 union 会引发与 join 相同的错误,而同源的 union 仍能正确获取。
由索引模型根据 Issue 内容生成。
描述
Summary
A + B never checks that namesake attributes share a lineage. The join of the same operands is rejected by the semantic check, but the union is accepted and merges unrelated entities whose keys happen to have the same name.
Union.create checks the connection, the primary-key names, and the overlap of secondary attributes, but it never calls assert_join_compatibility:
Union.create: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/expression.py#L1438-L1456assert_join_compatibility: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/condition.py#L223
Reproduction (master @ 207068d, MySQL 8.0)
@schema
class Mouse(dj.Manual):
definition = """
id : int32
---
mouse_name : varchar(32)
"""
@schema
class Probe(dj.Manual):
definition = """
id : int32
---
probe_serial : varchar(32)
"""
Mouse.insert([(1, "alpha"), (2, "beta")])
Probe.insert([(2, "P-0002"), (3, "P-0003")])
Mouse * Probe # rejected: different lineages
(Mouse.proj() + Probe.proj()).to_dicts() # accepted
The join is rejected:
DataJointError: Cannot join on attribute `id`: different lineages (djbugs_union.mouse.id vs djbugs_union.probe.id). Use .proj() to rename one of the attributes.
Mouse & Probe and Mouse.proj() * Probe.proj() are rejected with the same error. The union is accepted:
[{'id': 1}, {'id': 2}, {'id': 3}]
SELECT * FROM ((SELECT `id` FROM `djbugs_union`.`mouse`) UNION (SELECT `id` FROM `djbugs_union`.`probe`)) as `_u2`
Further consequences:
- Order-dependent lineage. The result's
idtakes the lineage of the first operand:mouse.idforMouse.proj() + Probe.proj(),probe.idwhen the operands are swapped. - Probe ids pass as mouse ids. The union then passes the semantic check against
Mouse:(Mouse.proj() + Probe.proj()) - Mousereturns[{'id': 3}], a probe id presented as a mouse id. - Late failure with secondary attributes.
Mouse + Probeis constructed without error and fails only at fetch, whenmake_sqlruns its internal left join (expression.py#L1469→join→assert_join_compatibility).
Expected
A + B should reject non-homologous namesakes when the expression is built, as A * B and A & B do. That is what the library and the docs state:
lineage.py: "Union (A + B): requires all namesakes to have matching lineage"- datajoint-docs
reference/specs/semantic-matching.md(§A + B) andexplanation/semantic-matching.md(operator table: Union, "Namesakes must be homologous")
Proposed fix
Call assert_join_compatibility(arg1, arg2) in Union.create, and add union cases to tests/integration/test_semantic_matching.py, which has none today:
- key-only operands;
- operands with secondary attributes;
- a homologous control case that must still work.
- 主要语言
- Python
- 星标
- 198
- 派生
- 103
- 平均合并
- 5 天 1 小时
- 30 天内合并 PR
- 12
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
datajoint/datajoint-python 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
datajoint/datajoint-python#1750 ·
维护者通常 5 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
datajoint/datajoint-python#1712 ·
维护者通常 5 天内回复
-
Decoding a <blob> value in an unknown format returns None instead of raising an error可能已有人在做 @godara-alt 于 3 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
datajoint/datajoint-python#1703 ·
维护者通常 5 天内回复
-
Character matrices with more than one row come back transposed from <blob>可能已有人在做 @godara-alt 于 2 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
datajoint/datajoint-python#1702 ·
维护者通常 5 天内回复
-
staged_insert1 stores object paths with the class name and an empty store name, so garbage collection can delete its objects可能已有人在做 @godara-alt 于 3 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
datajoint/datajoint-python#1701 ·
维护者通常 5 天内回复
查看 datajoint/datajoint-python 的全部 Issue
相似的 Issue
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
jxxghp/MoviePilot#7576 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
jbaruch/software-factory#266 ·
维护者通常 1 天内回复
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复