Reject constant defaults on primary-key attributes
メンテナーはふだん 5 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 84/100
調査の方向性
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時間
- マージ済み PR(30日)
- 12
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信