Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

JSON path type annotation is not portable: `data.n:int` works on PostgreSQL, raises on MySQL

未关闭
#1,563 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
mysql, postgresql, python
领域
databases

调研方向

Start with adapters/mysql.py around lines 872-874 and compare its return_type handling with the mapping in adapters/postgres.py. Reproduce the listed expressions against MySQL 8.0 and PostgreSQL 15, then check json-type.ipynb and reference/specs/type-system.md. Done means the accepted annotation vocabulary is consistent or clearly rejected across both adapters, with the canonical spelling documented.

由索引模型根据 Issue 内容生成。

描述

bug

The attr.path:type annotation accepted by translate_attribute takes a different vocabulary on each backend, with no indication of which is canonical. The same expression works on one and raises a SQL syntax error on the other.

Unrelated to #1561 and #1562, which are about hidden attributes. This one is about an ordinary visible json column.

Repro

@schema
class Doc(dj.Manual):
    definition = """
    doc_id : int32
    ---
    data : json
    """
Doc.insert1({"doc_id": 1, "data": {"system": "PyRat", "n": 7}})
expression MySQL 8.0 postgres:15
Doc.proj(n="data.n") '7' — str '7' — str
Doc.proj(n="data.n:int") QuerySyntaxError 7 — int
Doc.proj(n="data.n:unsigned") 7 — int 7 — int
Doc.proj(n="data.n:decimal(5,1)") Decimal('7.0') Decimal('7.0')

Cause

The two adapters treat return_type differently.

adapters/postgres.py maps the annotation onto a PostgreSQL type before casting:

pg_type = return_type.lower()
if pg_type in ("unsigned", "signed"):
    pg_type = "integer"

so it accepts MySQL's vocabulary and PostgreSQL's own.

adapters/mysql.py:872-874 passes it through verbatim:

return_clause = f" returning {return_type}" if return_type else ""
return f"json_value({quoted_col}, _utf8mb4'$.{path}'{return_clause})"

MySQL's JSON_VALUE ... RETURNING accepts only a fixed set — SIGNED, UNSIGNED, DECIMAL, CHAR, DATE and so on — and int is not among them, so the statement is invalid.

The effect is that the portable vocabulary is MySQL's, PostgreSQL silently tolerates a superset, and a pipeline developed against PostgreSQL can carry an annotation that fails the first time it runs on MySQL. Nothing in the docs or the error says so.

Suggested fix

Normalize in the MySQL adapter as PostgreSQL already does — map int / integer / bigint and similar onto the RETURNING vocabulary — and reject an unmappable annotation with a clear error naming the accepted set, rather than emitting SQL the server will refuse.

Settle which spelling is canonical and document it. json-type.ipynb and reference/specs/type-system.md are the places that would say so; neither currently does.

Also worth noting

Without an annotation, a numeric JSON field comes back as a string on both backends ('7', not 7) — both extraction functions return text. That is defensible, since JSON has no fixed scalar type, but it is undocumented and the annotation is the only remedy. Mentioned because anyone hitting the portability problem above arrived there by trying to fix this.

主要语言
Python
星标
197
派生
98
平均合并
1 天 23 小时
30 天内合并 PR
6

环境准备

  • 提供 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 摘要。