JSON path type annotation is not portable: `data.n:int` works on PostgreSQL, raises on MySQL
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 68/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 197
- Forks
- 98
- Merge moyen
- 1 j 23 h
- PR mergées (30 j)
- 6
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de datajoint/datajoint-python
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
datajoint/datajoint-python#1539 · 3 commentaires ·
-
JSON path equality against a non-string value: silently empty on MySQL, raises on PostgreSQLOuvertebug
Difficulté 3/5 1-2 jours Accessibilité débutants 75/100
datajoint/datajoint-python#1564 ·
-
enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
datajoint/datajoint-python#1562 · 2 commentaires ·
-
bug
Difficulté 3/5 1-2 jours Accessibilité débutants 75/100
datajoint/datajoint-python#1561 · 1 commentaire ·
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
datajoint/datajoint-python#1560 ·
Toutes les issues de datajoint/datajoint-python
Issues similaires
-
Claiming namespace apexdevOuvertenamespace operations
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
EclipseFdn/open-vsx.org#13737 ·
Les mainteneurs répondent en général sous 1 jour
-
Zero-token evaluations are treated as missing cost in selectionPeut-être pris @sylvesterkaczmarek l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
google-research/rrsi#6 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
aws-samples/sample-aws-genai-db-modernizer#294 ·
Les mainteneurs répondent en général sous 1 jour
-
feedback simulation workshop
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
githubnext/gh-aw-workshop#4174 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
WingedGuardian/GENesis-AGI#2852 ·
Les mainteneurs répondent en général sous 1 jour