A column copied by a foreign key loses the parent's core type (int32 becomes int)
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 25/100
調査の方向性
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), whichcompile_foreign_keyuses 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 intooriginal_type, soint32,int16,float64,varchar(n),date, and the rest are dropped.- On PostgreSQL,
compile_foreign_keypasses the comment toformat_column_definition, which ignores inline comments on that backend; the copied column is never added to theCOMMENT ON COLUMNstatements thatdeclare()(andalter()) run afterwards. JobsTablebuilds its key fromattr.original_type or attr.type; withoriginal_typelost 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 readingoriginal_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
Attribute.sql_commentrestores:{original_type}:when the attribute has one (falling back to:uuid:), so the copied column carries the same marker the parent was declared with.compile_foreign_keyrecords each copied column's comment in the declaration'scolumn_comments, so PostgreSQL emitsCOMMENT ON COLUMNfor it. On MySQLcolumn_comment_ddlreturnsNone, so nothing changes there.
- 主要言語
- Python
- スター
- 197
- フォーク
- 98
- 平均マージ
- 15時間 31分
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
datajoint/datajoint-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
datajoint/datajoint-python#1581 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
datajoint/datajoint-python#1539 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
_job_start_time records the populating host's local time, with no zone対応中かも @dimitri-yatsenko が今日担当しました。 オープン
datajoint/datajoint-python#1584 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
database.name should namespace schema names on MySQL, as it does on PostgreSQL対応中かも @dimitri-yatsenko が 3 日前に担当しました。 オープンfeature
難易度 4/5 3〜5日 初心者へのやさしさ 15/100
datajoint/datajoint-python#1582 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 40/100
datajoint/datajoint-python#1580 ·
メンテナーはふだん 1 日以内に返信
datajoint/datajoint-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
huggingface/peft#3955 ·
メンテナーはふだん 1 日以内に返信
-
author-page correction
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
acl-org/acl-anthology#10313 ·
メンテナーはふだん 1 日以内に返信
-
anime duplicate exception request-theme
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
LizardByte/ThemerrDB#8926 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
huggingface/transformers#49556 ·
メンテナーはふだん 1 日以内に返信
-
area/security bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
mozilla-ai/otari#2245 ·
メンテナーはふだん 1 日以内に返信