Public join(allow_nullable_pk=True) puts NULL into a primary key
Maintainer antworten meist innerhalb von 5 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 40/100
Rechercherichtung
Read the public join() signature and the left-join check in src/datajoint/expression.py (around lines 343 and 383-387), then the key-merging logic in src/datajoint/heading.py around lines 735-754. Follow the single internal caller in Aggregation.create (expression.py ~1367) to see what it actually needs, and read the docs at reference/specs/primary-keys.md lines 250-306 plus the extend() docs. Done means allow_nullable_pk is no longer reachable from the public join() while aggregation's left join still works, verified by the reproduction in the issue becoming impossible and the existing join/aggregation tests passing. Note this is an API decision between the two options, so confirm the preferred direction with a maintainer before coding.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
join(other, left=True, allow_nullable_pk=True) is part of the public signature, and it returns results whose primary key contains NULL. The heading still marks those key attributes as non-nullable, and later operators accept the result without complaint. A public call can therefore break the guarantee that every query result has a non-null primary key.
The parameter exists for internal use: its only caller is aggregation with exclude_nonmatching=False. The docstring and the docs (reference/specs/primary-keys.md, around lines 250–306) call it "primarily internal" and say "Users should generally avoid this parameter".
- Public signature: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/expression.py#L343
- Bypass of the left-join check: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/expression.py#L383-L387
- Key becomes
PK(A) ∪ PK(B): https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/heading.py#L735-L754 - Only internal caller: https://github.com/datajoint/datajoint-python/blob/207068d8c67dbc48a4496aa20c979a0a71cad9f6/src/datajoint/expression.py#L1367
Reproduction (master @ 207068d, MySQL 8.0)
@schema
class Subject(dj.Manual):
definition = """
subject_id : int32
---
species : varchar(32)
"""
@schema
class Session(dj.Manual):
definition = """
session_id : int32
---
-> [nullable] Subject
session_date : date
"""
@schema
class Trial(dj.Manual):
definition = """
-> Session
trial_id : int32
---
response_time : float32
"""
Subject.insert([(1, "mouse"), (2, "rat")])
Session.insert([dict(session_id=10, subject_id=1, session_date="2026-01-01"),
dict(session_id=11, subject_id=None, session_date="2026-01-02")])
Trial.insert([(10, 1, 0.5), (10, 2, 0.6)])
Session.join(Trial, left=True) # rejected (A must determine B)
q = Session.join(Trial, left=True, allow_nullable_pk=True)
q.primary_key # ['session_id', 'trial_id']
q.keys() # [{'session_id': 11, 'trial_id': None}, {'session_id': 10, 'trial_id': 1}, ...]
q.heading reports trial_id as nullable=False. A nullable secondary foreign key gives the same result: Subject.join(Session, left=True, allow_nullable_pk=True) has primary key ['subject_id', 'session_id'] and contains {'subject_id': 2, 'session_id': None, ...}. These results are accepted as operands of * and & without complaint.
Expected
No public operator should be able to produce a primary key containing NULL. Make the parameter private:
- Option 1: pass it through an internal-only argument or helper used by
Aggregation.create. - Option 2: remove it from
join()and build the aggregation's left join directly.
The extend() docs already describe it as "an internal mechanism".
Related: #1708. Its audit says that join keys always come from the operands' keys, and that dj.U is the only operator that puts non-key attributes into a key. This parameter is a second way to get NULL into a key.
- 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