JSON path equality against a non-string value: silently empty on MySQL, raises on PostgreSQL
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 75/100
Direção de pesquisa
Start in condition.py around prep_value at line 336, then trace adapter.json_path_expr for the MySQL and PostgreSQL implementations. Reproduce the listed restrictions against both backends and add regression coverage for string, integer, and boolean values. Done means JSON-path comparisons behave consistently across backends and never silently return wrong rows.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Table & {"json_attr.field": value} only behaves correctly when value is a string. A Python bool returns the wrong answer on MySQL and raises on PostgreSQL; a Python int raises on PostgreSQL.
Sibling of #1563 — same root (JSON extraction yields text), different side: that one is the :type annotation on projection, this one is the Python value on restriction.
Repro
@schema
class E(dj.Manual):
definition = """
name : varchar(32)
---
s : json
"""
E.insert([
{"name": "a", "s": {"vendor": "Acme", "ch": 64, "cal": True}},
{"name": "b", "s": {"vendor": "Other", "ch": 16, "cal": False}},
])
Each row should select ['a']:
| restriction | MySQL 8.0 | postgres:15 |
|---|---|---|
& {"s.vendor": "Acme"} |
['a'] |
['a'] |
& {"s.ch": 64} |
['a'] |
UndefinedFunction: operator does not exist: text = integer |
& {"s.ch": "64"} |
['a'] |
['a'] |
& {"s.cal": True} |
[] |
UndefinedFunction: operator does not exist: text = boolean |
& {"s.cal": "true"} |
['a'] |
['a'] |
The MySQL boolean row is the serious one: no error, no rows, and the natural reading of an empty result is "nothing is calibrated."
Cause
adapter.json_path_expr yields json_value(...) / jsonb_extract_path_text(...), both of which return text. prep_value (condition.py:336) then renders the Python value by its own type, so the comparison becomes text = <non-text>:
- PostgreSQL refuses the comparison outright.
- MySQL coerces for numerics, which is why
64happens to work, but compares the extractedtrueagainst1for a bool and matches nothing.
The asymmetry is invisible to a user: the same expression is correct, wrong, or an error depending on the value's Python type and the backend.
Suggested fix
On the JSON-path branch of prep_value, render the comparison value as text — or cast the extraction to the value's type — so that True, 64 and "Acme" all behave the same way on both backends.
Whichever way, a bool must not silently match nothing. If a given comparison cannot be made portable, raising is acceptable; returning the wrong rows is not.
Documentation
This is almost certainly why tutorials/advanced/json-type.ipynb teaches "Filtering on JSON Content — fetch then filter in Python" and lists "Filter in Python" as an inherent property of JSON in its Design Guidelines. Server-side filtering does work, with the value passed as a string; the tutorial's advice reads as a limitation of the type rather than of this behavior. Worth revisiting together.
- Linguagem predominante
- Python
- Estrelas
- 197
- Forks
- 98
- Merge médio
- 23h 9min
- PRs com merge (30d)
- 6
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de datajoint/datajoint-python
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
datajoint/datajoint-python#1539 · 3 comentários ·
-
Python 3.15 ships Oct 9 and we cap below it; 3.10 went EOL Oct 1Talvez já em andamento @dimitri-yatsenko assumiu há 4 dias. Abertaenhancement
datajoint/datajoint-python#1569 · 1 responsável ·
-
bug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 68/100
datajoint/datajoint-python#1563 ·
-
enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
datajoint/datajoint-python#1562 · 2 comentários ·
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 75/100
datajoint/datajoint-python#1561 · 1 comentário ·
Todas as issues de datajoint/datajoint-python
Issues semelhantes
-
Broken link in index.rstAbertadocumentation
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 65/100
ansys/pydpf-core#3547 ·
Mantenedores costumam responder em até 1 dia
-
core
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
vectorize-io/hindsight#5457 ·
Mantenedores costumam responder em até 1 dia
-
[Bug]: LangChain drops OpenAI Responses text blocks from session recordingTalvez já em andamento @ktz03 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
volcengine/OpenViking#5806 ·
Mantenedores costumam responder em até 1 dia
-
HTML: <template> content is extracted as document textTalvez já em andamento @ryanmeowy assumiu hoje. Abertabug html
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 82/100
docling-project/docling#4714 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
APIv2 event data accepts a non-string reply and a NaN upper_boundTalvez já em andamento @awss1i assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
freedomofpress/securedrop#7946 · 1 comentário ·
Mantenedores costumam responder em até 2 dias