Two foreign keys that bring the same attribute name with different lineages are merged into one column
Maintainer antworten meist innerhalb von 5 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 72/100
Rechercherichtung
Start in src/datajoint/declare.py around lines 487-488 (where the second namesake attribute is silently skipped) and 512-516 (where the lineage map is overwritten by the last foreign key). Read how the heading and lineage map are built while foreign keys are processed, then reproduce with the Mouse/Probe/Implant example on MySQL. Done means a DataJointError naming the attribute and both lineages is raised for differing lineages, the homologous Recording/subject_id merge still works, the renamed workaround is tested, and the rule is documented in table-declaration.md.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
When two foreign keys of one table bring attributes with the same name but different lineages, the declaration is accepted, and the two attributes become one shared column. The column then carries both foreign key constraints, and ~lineage records only the lineage of the foreign key declared last.
Merging namesakes is correct when they are homologous: two parents that both inherit subject_id from Subject should share the column. It is wrong when the namesakes come from unrelated parents.
- The second attribute is silently skipped: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/declare.py#L487-L488
- The lineage map is overwritten by the last foreign key: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/declare.py#L512-L516
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)
"""
@schema
class Implant(dj.Manual): # expected: DataJointError; actual: accepted
definition = """
-> Mouse
-> Probe
---
implant_date : date
"""
Implant gets one key column, id, constrained by both parents:
CREATE TABLE `implant` (
`id` int NOT NULL COMMENT ':int32:',
`implant_date` date NOT NULL COMMENT ':date:',
PRIMARY KEY (`id`),
CONSTRAINT `implant_ibfk_1` FOREIGN KEY (`id`) REFERENCES `mouse` (`id`) ...,
CONSTRAINT `implant_ibfk_2` FOREIGN KEY (`id`) REFERENCES `probe` (`id`) ...
)
~lineage holds ('implant', 'id', 'djbugs_fkmerge.probe.id'). With the foreign keys in the opposite order, it holds mouse.id.
Consequences:
- Joins with a declared parent fail.
Implant * Mouseis rejected (different lineages (djbugs_fkmerge.probe.id vs djbugs_fkmerge.mouse.id)), althoughMouseis a declared parent.Implant * Probeworks. - Mice and probes are tied by number. An implant can only pair mouse N with probe N. A second implant for mouse 1 raises
DuplicateError. - Control case.
Recordingwith-> Sessionand-> Electrode, both carryingsubject_idfromSubject, merges correctly with lineagesubject.subject_id. A fix must reject only differing lineages.
Expected
The declaration should be rejected with a DataJointError. The error should name the attribute and its two lineages, and suggest renaming one side, e.g. -> Probe.proj(probe_id='id').
Proposed fix
When a foreign key brings an attribute that is already in the heading, compare the two lineages:
- Equal: keep the current behavior and share the column.
- Different: raise.
Document the rule in table-declaration.md, and add tests for:
- the rejected case;
- the homologous merge;
- the renamed workaround.
- Vorherrschende Sprache
- Python
- Sterne
- 198
- Forks
- 107
- Ø Merge
- 4 T. 7 Std.
- Gemergte PRs (30 T.)
- 12
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus datajoint/datajoint-python
-
bug triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
datajoint/datajoint-python#1775 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
MySQL: with use_tls=False, 2.3.6 needs the cryptography package to log in to MySQL 8Evtl. vergeben @dimitri-yatsenko hat das vor 5 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
datajoint/datajoint-python#1750 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
datajoint/datajoint-python#1747 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
Reject constant defaults on primary-key attributesEvtl. vergeben @godara-alt hat das vor 4 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
datajoint/datajoint-python#1712 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
Decoding a <blob> value in an unknown format returns None instead of raising an errorEvtl. vergeben @godara-alt hat das vor 9 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
datajoint/datajoint-python#1703 ·
Maintainer antworten meist innerhalb von 5 Tagen
Alle Issues in datajoint/datajoint-python
Ähnliche Issues
-
[Bug]: test_remote_realpath_uses_argument_vector fails on Windows with Python 3.13+ (ntpath.isabs)Evtl. vergeben @gouyu-hou hat das heute übernommen. Offentriage/confirmed
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
agentscope-ai/agentscope#4397 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
area/profiles area/sessions comp/desktop desktop/chat desktop/sessions P2 type/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
NousResearch/hermes-agent#161712 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[New Check]: postgresql_flexible_server_public_network_access_disabledEvtl. vergeben @pouria-l hat das heute übernommen. Offenfeature-request status/needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
prowler-cloud/prowler#13615 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
SACGF/variantgrid#2941 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
linkedin/Liger-Kernel#1730 ·
Maintainer antworten meist innerhalb von 3 Tagen