Union does not check lineage: unrelated tables whose keys share a name are merged
Les mainteneurs répondent en général sous 5 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 78/100
Piste de recherche
Pars de Union.create dans src/datajoint/expression.py et compare-le au chemin de join qui appelle assert_join_compatibility dans src/datajoint/condition.py. Reproduis l'extrait, puis fais en sorte que union effectue la même vérification de lignée avant de fusionner les homonymes et ajoute des cas de clé seule, d'attribut secondaire et de contrôle homologue à tests/integration/test_semantic_matching.py. Terminé signifie que les unions avec une lignée non concordante lèvent la même erreur que les joins, tandis que les unions homologues récupèrent toujours correctement.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
A + B never checks that namesake attributes share a lineage. The join of the same operands is rejected by the semantic check, but the union is accepted and merges unrelated entities whose keys happen to have the same name.
Union.create checks the connection, the primary-key names, and the overlap of secondary attributes, but it never calls assert_join_compatibility:
Union.create: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/expression.py#L1438-L1456assert_join_compatibility: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/condition.py#L223
Reproduction (master @ 207068d, MySQL 8.0)
@schema
class Mouse(dj.Manual):
definition = """
id : int32
---
mouse_name : varchar(32)
"""
@schema
class Probe(dj.Manual):
definition = """
id : int32
---
probe_serial : varchar(32)
"""
Mouse.insert([(1, "alpha"), (2, "beta")])
Probe.insert([(2, "P-0002"), (3, "P-0003")])
Mouse * Probe # rejected: different lineages
(Mouse.proj() + Probe.proj()).to_dicts() # accepted
The join is rejected:
DataJointError: Cannot join on attribute `id`: different lineages (djbugs_union.mouse.id vs djbugs_union.probe.id). Use .proj() to rename one of the attributes.
Mouse & Probe and Mouse.proj() * Probe.proj() are rejected with the same error. The union is accepted:
[{'id': 1}, {'id': 2}, {'id': 3}]
SELECT * FROM ((SELECT `id` FROM `djbugs_union`.`mouse`) UNION (SELECT `id` FROM `djbugs_union`.`probe`)) as `_u2`
Further consequences:
- Order-dependent lineage. The result's
idtakes the lineage of the first operand:mouse.idforMouse.proj() + Probe.proj(),probe.idwhen the operands are swapped. - Probe ids pass as mouse ids. The union then passes the semantic check against
Mouse:(Mouse.proj() + Probe.proj()) - Mousereturns[{'id': 3}], a probe id presented as a mouse id. - Late failure with secondary attributes.
Mouse + Probeis constructed without error and fails only at fetch, whenmake_sqlruns its internal left join (expression.py#L1469→join→assert_join_compatibility).
Expected
A + B should reject non-homologous namesakes when the expression is built, as A * B and A & B do. That is what the library and the docs state:
lineage.py: "Union (A + B): requires all namesakes to have matching lineage"- datajoint-docs
reference/specs/semantic-matching.md(§A + B) andexplanation/semantic-matching.md(operator table: Union, "Namesakes must be homologous")
Proposed fix
Call assert_join_compatibility(arg1, arg2) in Union.create, and add union cases to tests/integration/test_semantic_matching.py, which has none today:
- key-only operands;
- operands with secondary attributes;
- a homologous control case that must still work.
- Langage dominant
- Python
- Étoiles
- 198
- Forks
- 103
- Merge moyen
- 5 j 1 h
- PR mergées (30 j)
- 12
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
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
datajoint/datajoint-python#1750 ·
Les mainteneurs répondent en général sous 5 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
datajoint/datajoint-python#1712 ·
Les mainteneurs répondent en général sous 5 jours
-
Decoding a <blob> value in an unknown format returns None instead of raising an errorPeut-être pris @godara-alt l’a pris il y a 3 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
datajoint/datajoint-python#1703 ·
Les mainteneurs répondent en général sous 5 jours
-
Character matrices with more than one row come back transposed from <blob>Peut-être pris @godara-alt l’a pris il y a 2 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
datajoint/datajoint-python#1702 ·
Les mainteneurs répondent en général sous 5 jours
-
staged_insert1 stores object paths with the class name and an empty store name, so garbage collection can delete its objectsPeut-être pris @godara-alt l’a pris il y a 3 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
datajoint/datajoint-python#1701 ·
Les mainteneurs répondent en général sous 5 jours
Toutes les issues de datajoint/datajoint-python
Issues similaires
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 2 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
jxxghp/MoviePilot#7576 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
jbaruch/software-factory#266 ·
Les mainteneurs répondent en général sous 1 jour
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Les mainteneurs répondent en général sous 1 jour