Mapping restriction naming a hidden attribute silently drops the predicate
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 75/100
Piste de recherche
Read condition.py around lines 347 and 409, then compare the hidden-attribute lookup with the fallback in heading.py:398-404. Verify restriction tests for hidden and absent attributes on MySQL and PostgreSQL, while confirming visible JSON-path restrictions remain unchanged; done means a mapping restriction on an existing hidden column produces its predicate and an absent column is still ignored.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
A mapping restriction naming an attribute that exists on the table but is hidden has its predicate dropped, and every row is returned.
Nothing about JSON is involved. Earlier revisions of this issue demonstrated it with _prov, whose JSON type made it look like a JSON-path problem; it is not.
Repro — no JSON
@schema
class Comp(dj.Computed): # with config.jobs.add_job_metadata on
definition = """
-> Src
---
val : int32
"""
Two populated rows. _job_version is a varchar(64):
| restriction | MySQL 8.0 | postgres:15 |
|---|---|---|
Comp & {"_job_version": "nonexistent"} |
2 | 2 |
Comp & "_job_version IS NOT NULL" |
2 | 2 |
The first should match nothing. The emitted SQL carries no predicate at all. Same on both backends, so the defect is backend-agnostic, and it applies to _job_start_time, _job_duration and _prov equally.
What is not broken
Worth stating, because the earlier framing of this issue implied otherwise: JSON path restriction works correctly and portably on a visible attribute.
Doc & {"data.system": "PyRat"} # `data : json`
returns 1 of 2 rows on MySQL and on PostgreSQL alike. translate_attribute (condition.py:59-61) hands the path to adapter.json_path_expr, which emits json_value() on one and jsonb_extract_path_text() on the other. That machinery is fine and is not what this issue is about.
The reason a JSON-typed hidden attribute looks worse is only that the portable spelling runs through the mapping form, which is the form being dropped — so for _prov the workaround has to be backend-specific SQL. That is a consequence of this bug, not a separate JSON defect.
Cause
condition.py:409:
common_attributes = set(c.split(".", 1)[0] for c in condition).intersection(query_expression.heading.names)
if not common_attributes:
return not negate # no matching attributes -> evaluates to True
heading.names is visible-only, so a hidden name lands in the same bucket as an attribute the table does not have.
Suggested fix
Match against the names present in _attributes rather than names, so a hidden attribute resolves instead of being discarded.
The two cases are different facts and are distinguishable:
scan_idonSession— absent from_attributesentirely. Ignoring it is deliberate and must stay:Session & keyhas to work whenkeycarries attributes from a more detailed downstream table, andmake()depends on that._job_versionon a Computed table — present in_attributes, filtered only out ofnames. The column exists; the caller named a real thing.
So the key-passing idiom is untouched. A dict reaching & can only acquire a hidden name by hand: every key DataJoint produces — keys(), to_dicts(), fetch1(), key_source — is built from the visible heading, so no generated query changes.
Nothing hidden becomes readable by this. Restriction on these columns already works through the string form; #1562 is the separate question of reading values back.
One obstacle in the same change: condition.py:347 does query_expression.heading[key_match["attr"]].uuid, and Heading.__getitem__ resolves through attributes, so it raises KeyError on a hidden name. It needs the _attributes fallback Heading.as_sql already uses (heading.py:398-404).
Noticed in passing, not filed
Doc & {"data": {"system": "PyRat", "n": 7}} — restricting by a whole JSON object rather than a path — raises QuerySyntaxError on both backends. prep_value only special-cases a dict value when the key is a JSON path (condition.py:343-344), so a whole-object comparison falls through and emits invalid SQL. It errors rather than answering wrongly, so it is a poor message rather than a correctness problem. Mentioned only so the next person who hits it knows it is understood.
Documentation
reference/specs/boundary-provenance.md, how-to/record-data-origin.md, the data-entry tutorial and reference/specs/job-metadata.md advertised the mapping form on _prov. Corrected in datajoint/datajoint-docs#288.
- 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 ·
-
JSON path type annotation is not portable: `data.n:int` works on PostgreSQL, raises on MySQLOuvertebug
Difficulté 4/5 3-5 jours Accessibilité débutants 68/100
datajoint/datajoint-python#1563 ·
-
enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
datajoint/datajoint-python#1562 · 2 commentaires ·
-
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
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
zhuima/awesome-cloudflare#237 ·
-
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