Reject constant defaults on primary-key attributes
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 compile_attribute 入手,在 declare.py 中追踪主键属性默认值的分类方式。补充测试,覆盖常量键默认值、CURRENT_TIMESTAMP 键默认值,以及保持不变的次要属性默认值。完成标准是:常量键默认值在声明时被拒绝,并报错指出属性名称且告知用户移除默认值,同时生成的默认值和次要属性默认值仍被接受。
由索引模型根据 Issue 内容生成。
描述
Problem
The definition language accepts a constant default on a primary-key attribute. compile_attribute in declare.py rejects only nullable key attributes; any other default above the --- separator compiles to NOT NULL DEFAULT <value>.
A constant default lets an insertion omit part of an entity's identity. The database then fills in the same value for every such insertion: the first one succeeds silently with the default key, and the next one collides.
Reproduction
DataJoint 2.3.5.dev, MySQL 8.0:
@schema
class Probe(dj.Manual):
definition = """
probe_id = 1 : int32
---
label : varchar(16)
"""
Probe.insert1({"label": "x"}) # accepted, no key supplied
Probe.to_dicts() # [{'probe_id': 1, 'label': 'x'}]
Proposed rule
- Reject constant defaults on primary-key attributes at declaration, with an error naming the attribute.
- Keep allowing generated defaults, values produced afresh at each insertion.
CURRENT_TIMESTAMPis the one the definition language accepts today, andvisit_ts = CURRENT_TIMESTAMP : datetimein the key works as a generated key. A generated UUID default would fall under the same rule if it is ever supported.
Generated keys remain surrogates, with the costs the docs already describe in Explicit keys, no auto-increment: a repeated insertion makes a second entity instead of a key collision. They are allowed but not recommended.
This matches the rule in the Relational Workflow Model specification: key attributes are never null and take no constant default; a nullable attribute's only default is null; an attribute without a default must be supplied.
Scope
- The check runs at declaration time only, so existing tables are unaffected. A schema that declares a key attribute with a constant default will fail to declare after the change, which is the intent; the error message should say to remove the default.
- Foreign-key attributes in the key are unaffected, since dependencies take no defaults.
Tests
- A declaration with
k = 1 : int32above the separator raises. - A declaration with
ts = CURRENT_TIMESTAMP : datetimeabove the separator succeeds. - Defaults on secondary attributes are unchanged.
- 主要语言
- 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 小时 新手友好度 78/100
datajoint/datajoint-python#1747 ·
维护者通常 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 天内回复