Reject constant defaults on primary-key attributes
Maintainer thường phản hồi trong vòng 5 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
Hướng nghiên cứu
Bắt đầu với compile_attribute trong declare.py và lần theo cách các giá trị mặc định của thuộc tính khóa chính được phân loại. Bổ sung kiểm thử cho giá trị mặc định hằng của khóa, giá trị mặc định CURRENT_TIMESTAMP của khóa và giá trị mặc định không thay đổi của thuộc tính phụ. Công việc được xem là hoàn tất khi giá trị mặc định hằng của khóa bị từ chối lúc khai báo bằng lỗi nêu tên thuộc tính và yêu cầu người dùng xóa giá trị mặc định, trong khi các giá trị mặc định được tạo tự động và của thuộc tính phụ vẫn được chấp nhận.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 198
- Fork
- 103
- Merge trung bình
- 5 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 12
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của datajoint/datajoint-python
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
datajoint/datajoint-python#1750 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datajoint/datajoint-python#1747 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Decoding a <blob> value in an unknown format returns None instead of raising an errorCó thể đã có người làm @godara-alt đã nhận 3 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datajoint/datajoint-python#1703 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Character matrices with more than one row come back transposed from <blob>Có thể đã có người làm @godara-alt đã nhận 2 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datajoint/datajoint-python#1702 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
staged_insert1 stores object paths with the class name and an empty store name, so garbage collection can delete its objectsCó thể đã có người làm @godara-alt đã nhận 3 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
datajoint/datajoint-python#1701 ·
Maintainer thường phản hồi trong vòng 5 ngày
Tất cả issue của datajoint/datajoint-python
Issue tương tự
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
jxxghp/MoviePilot#7576 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
jbaruch/software-factory#266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày