Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

A column copied by a foreign key loses the parent's core type (int32 becomes int)

未關閉
#1,578 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@dimitri-yatsenko 已經在處理了。

開始於 2026年10月9日。

  • #1579 來自 @dimitri-yatsenko —— 未關閉

評估

難度
3/5
預估耗時
半天
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
mysql, postgresql, python
領域
database

研究方向

Start with Attribute.sql_comment in heading.py, then follow compile_foreign_key and the PostgreSQL path through format_column_definition and column_comments, plus JobsTable's use of original_type. Run the reproduction script to confirm original_type is None on the child. Done means copied columns keep their :int32:-style marker and PostgreSQL emits COMMENT ON COLUMN for them. PR #1579 is already open against this issue, so check it before starting.

由索引模型根據 Issue 內容生成。

描述

Summary

A column copied into a child table by a foreign key loses the parent's core type. The parent's subject_id : int32 is stored with the comment marker :int32:, which Heading reads back as original_type; the child's copy of the column is created without the marker, so the child's heading reports the native SQL type (int) and original_type is None. Every table built from the child inherits the loss, which is most visible in jobs tables: creating one for an auto-populated table logs a portability warning for each inherited key attribute, about "native types" the user never declared.

On PostgreSQL the copied column loses its comment entirely (marker and text), because the comment is passed inline to a backend that sets comments with COMMENT ON COLUMN, and the copied columns are not among those it comments.

Reproduction

DataJoint 2.3.5.dev2 (master), MySQL 8.0:

import datajoint as dj

schema = dj.Schema("scratch_fk_core_types")

@schema
class Subject(dj.Manual):
    definition = """
    subject_id : int32
    """

@schema
class Session(dj.Manual):
    definition = """
    -> Subject
    session_idx : int16
    """

@schema
class Summary(dj.Computed):
    definition = """
    -> Session
    ---
    n : int32
    """

    def make(self, key):
        self.insert1(dict(key, n=1))

for t in (Subject, Session, Summary):
    print(t.__name__, {a: t.heading[a].original_type for a in t.heading.primary_key})
Summary.jobs  # creates the jobs table

Output:

Subject {'subject_id': 'int32'}
Session {'subject_id': None, 'session_idx': 'int16'}
Summary {'subject_id': None, 'session_idx': None}
[WARNING]: Native type 'int' is used in attribute 'subject_id'. Consider using a core DataJoint type for better portability.
[WARNING]: Native type 'smallint' is used in attribute 'session_idx'. Consider using a core DataJoint type for better portability.

The column comments in information_schema.columns confirm it: subject.subject_id is :int32:, while session.subject_id, summary.subject_id and summary.session_idx are empty.

Cause

  • Attribute.sql_comment (heading.py), which compile_foreign_key uses for the copied column's comment, re-adds only the :uuid: marker. Heading parsing has already moved every other core type out of the comment into original_type, so int32, int16, float64, varchar(n), date, and the rest are dropped.
  • On PostgreSQL, compile_foreign_key passes the comment to format_column_definition, which ignores inline comments on that backend; the copied column is never added to the COMMENT ON COLUMN statements that declare() (and alter()) run afterwards.
  • JobsTable builds its key from attr.original_type or attr.type; with original_type lost on inherited attributes, it falls back to the SQL type and declaration warns.

Impact

  • Child headings report native SQL types for inherited key attributes (describe() and anything reading original_type).
  • A spurious "Native type" warning per inherited key attribute whenever a jobs table is created, for nearly every auto-populated table.
  • On PostgreSQL, inherited columns also lose the parent's comment text.

Tables declared before a fix keep their stored comments; the fix applies to tables declared after it.

Proposed fix

  1. Attribute.sql_comment restores :{original_type}: when the attribute has one (falling back to :uuid:), so the copied column carries the same marker the parent was declared with.
  2. compile_foreign_key records each copied column's comment in the declaration's column_comments, so PostgreSQL emits COMMENT ON COLUMN for it. On MySQL column_comment_ddl returns None, so nothing changes there.
主要語言
Python
星號
197
分支
98
平均合併
15 小時 31 分鐘
30 天內合併 PR
9

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

datajoint/datajoint-python 的其他 Issue

查看 datajoint/datajoint-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。