Master–part: reject parts the master does not own, and insert part rows only with their master
Los mantenedores suelen responder en 5 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 28/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- databases, documentation
Línea de trabajo
Start with item 1: read the insert guard in src/datajoint/table.py and the Part implementation in src/datajoint/user_tables.py, then examine tests/integration/test_autopopulate.py. The first slice is done when computed-part inserts inherit the master’s _allow_insert behavior and a part-specific integration test passes. The remaining items depend on other issues and span transactions, ownership checks, cascades, and specification updates.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
A master row and its part rows are one entity. A part belongs to its master through a dependency in the part's primary key, has its master's tier, and is written in the transaction that writes its master row. A table that depends on the master can then read the whole set of parts and know it is complete and final. The docs state this rule (Relational Workflow Model, "Workflow steps and table tiers": a part "inherits its master's tier and is written in the same transaction"; AutoPopulate spec §4.3, rule 1: "Direct inserts into an auto-populated table are rejected at runtime"). The library holds it only for the rows populate() writes inside make(). On every other path a part row can be added to an existing master at any time, so a result computed from "all parts of this master" can be computed from a partial set, or stay in place after its inputs changed, with nothing recording either.
Items 1 to 4 were read, not run: each comes from reading master at b2994e5e and its tests, and each sketch is the failing test to write first. The schema-name case in item 4 has an executed reproduction in #1719. Entry, Ingest, and Compute are the tier names. In current code the classes are dj.Manual, dj.Imported, and dj.Computed, and dj.Entry, dj.Ingest, and dj.Compute name the same classes (#1546); the sketches use the new names.
Inserts, declarations, and spec text that separate a part from its master
The sketches for items 1 and 2 share these tables:
@schema
class Session(dj.Entry):
definition = """
session_id : int32
"""
class Trial(dj.Part):
definition = """
-> master
trial_id : int32
"""
@schema
class Segmentation(dj.Compute):
definition = """
-> Session
"""
class Roi(dj.Part):
definition = """
-> master
roi_id : int32
"""
def make(self, key):
self.insert1(key)
self.Roi.insert1({**key, "roi_id": 1})
-
1. Parts of Compute and Ingest masters accept direct inserts outside
make().Segmentation.Roi.insert(rows)succeeds for any existing master key withoutallow_direct_insert=True, so a computed result gains rows that nomake()produced.- Where: the guard at
src/datajoint/table.py:874readsgetattr(self, "_allow_insert", True). OnlyAutoPopulatedefines the flag (autopopulate.py:105, set on the master class at:682and:753);Part(user_tables.py:196-262) defines none.test_allow_insert(tests/integration/test_autopopulate.py:106) pins the guard for masters, and no test covers a part. - Change: give
Partan_allow_insertproperty that returnsgetattr(self._master, "_allow_insert", True), and add a part case besidetest_allow_insert. The flag is set per class, so insidemake()a part row for another master key still passes. - Compatibility: breaking for code that back-fills computed parts directly;
allow_direct_insert=Truerestores it. Warn for one minor release first. Adj.FreeTableopened on an auto-populated table, master or part, also passes the guard becauseFreeTabledefines no flag; that bypass is tracked separately.
Session.insert1({"session_id": 1}) Segmentation.populate() Segmentation.Roi.insert1({"session_id": 1, "roi_id": 2}) # accepted today; expected: DataJointError, as Segmentation.insert1 raises - Where: the guard at
-
2. Parts of an Entry master can be inserted in any later transaction. A
populate()that runs between the master's commit and the parts' commit computes from a partial set, and a part row added afterwards changes the inputs of results that stay in place.- Where:
Parthas no insert override (user_tables.py:196-262), andtable.py:874is the only insert guard. The master-part spec §2.1 calls atomicity for these masters "a convention rather than an enforced guarantee".tests/integration/test_cascade_delete.py:330-332inserts a master, then its parts, as separate statements. - Change: first step,
Part.inserton a part of an Entry or Lookup master raises unlessself.connection.in_transaction, with an explicit override for repairs. That checks only that a transaction is open. The full rule also requires that the open transaction inserted the referenced master rows, which needs the inserted master keys recorded per transaction on the connection. #711 (closed for inactivity) proposed one call that inserts a master with its parts. - Compatibility: breaking for every script that inserts an Entry master and its parts as separate statements. Warn for one minor release, then raise.
Session.insert1({"session_id": 2}) Session.Trial.insert1({"session_id": 2, "trial_id": 1}) # accepted today; expected: DataJointError with schema.connection.transaction: # passes before and after the change Session.insert1({"session_id": 3}) Session.Trial.insert1({"session_id": 3, "trial_id": 1}) - Where:
-
3. A part that its master does not own is declared without error. A
dj.Partwhose primary key carries no dependency on its master or on a sibling part (the reference sits below---, or is absent) has a key that identifies no master row, yet delete, drop, and the cascade treat it as a part.- Where:
Partoverrides no_declare_check, and the base hook is empty (table.py:203-217);schemas.py:264binds the master by class nesting alone.test_upward_u3_nonprimary_master_fk(tests/integration/test_cascade_integrity.py:118-156) declares-> masterbelow---and pins it. - Change: #1620 (open, closes #1619) adds the ownership rule and a warning at declaration. Raise
DataJointErrorin the minor release after the warning.fk_attribute_mapcannot decide ownership because it keeps one parent per attribute (declare.py:512-516); #1620 passes a per-reference list to the hook. - Compatibility: deprecation path. Only new declarations fail: a table that already exists is not declared again (
schemas.py:303).
@schema class Probe(dj.Entry): definition = """ probe_id : int32 """ class Note(dj.Part): # declared today; expected: DataJointError definition = """ note_id : int32 --- -> master """ - Where:
-
4. Delete, drop, and the cascade find a part's master by the table name, not by ownership. #1719 reports the schema-name case (a name with a non-word character, such as
parts-check, hides every part), and #1728 (open) fixes the pattern. This item adds the case #1728 leaves: a part the master does not own (item 3) still matches its master by name, so the delete check refuses to delete its rows unless master rows are deleted too, and the drop check refuses to drop it before the master, although its key identifies no master row.- Where:
extract_master(dependencies.py:36) matches the name only. Callers:table.py:1213(delete check),table.py:1332(drop check),diagram.py:844and:900(cascade from part to master),dependencies.py:64and:77(topo_sort). #1620 movestopo_sortto the ownership rule and leaves the delete, drop, and cascade call sites matching by name. - Change: after #1728 and #1620, move the delete, drop, and cascade call sites to the ownership rule that #1620 introduces.
- Compatibility: none for owned parts. A part the master does not own stops being treated as its part by delete, drop, and the cascade, which the declaration warning in #1620 announces.
- Where:
-
5. The master-part spec contradicts the library and itself. §2.2 says "Part tables have implicit foreign key to master" (
master-part.md:106); the library adds none, and the reference exists only where the definition writes it. §4.5 describes a master that "is a part of a higher-level master" (:238) and §7.4 says "Part tables cannot have their own parts" (:376). §7.1 advises against parts that "reference multiple masters" (:341), and the part in the §3.3 example references its own master and a part of another master (:161-165). §2.1 says parts "should be deleted/dropped with their master" (:86).- Change: edit the page in place in
datajoint-docs; no library change. Compatibility: none.
- Change: edit the page in place in
Tracked elsewhere: a delete that removes some of a master's parts (#1760), a part that references a table downstream of its own master (#1619), and self.upstream reaching the parts of an ancestor master (#1481).
Two findings on parts belong to other tracking issues. contents declared on the parts of a Lookup master is ignored, or committed apart from the master's rows: #1772. Tier detection reports Part where a part has its master's tier, and no public accessor returns that tier: #1773.
Docs pages that change with these items
| Page | Section | Change |
|---|---|---|
| Master-Part Relationships Specification | §1.4 Master Reference | State ownership: a dependency on the master, or on another part of it, in the part's primary key; any other part declaration is rejected (item 3) |
| §2.1 Compositional Integrity | "Should be deleted" becomes "are deleted"; the sentence that calls atomicity for Manual masters a "convention" goes when item 2 ships | |
| §2.2 Foreign Key Behavior | No implicit foreign key (item 5) | |
| §3.1 Master-First Insertion | Rewrite in the transaction form of §3.2 (item 2) | |
| §3.3 Computed Tables with Parts | Part inserts outside make() are rejected (item 1) |
|
| §4.5, §7.1, §7.4 | Resolve the contradictions in item 5; replace the "Avoid when" list with the criterion: one step produces the set, and downstream tables need it complete | |
| Table Declaration Specification | §8.4 Constraints | "Parts must reference their master" becomes "in the primary key", and says it is checked (item 3) |
| Data Manipulation Specification | §2.6 Auto-Populated Tables | The insert guard covers parts (item 1) |
| §6.1 Inserting into Part Tables | The example inserts master and parts as two statements; use one transaction (item 2) | |
| §9.3 Use Transactions for Related Inserts | skip_duplicates=True on the master adds parts to a master that may already exist (item 2) |
|
| AutoPopulate Specification | §4.3, rule 1; §6 Part Tables | Until item 1 ships, say the guard covers masters only |
| Relational Workflow Model | "Workflow steps and table tiers"; "Master-part relationships" | "Written in the same transaction" and "without application code" hold for Entry masters only after item 2; qualify until then |
| Data Integrity | "5. Compositional integrity" | Same sentence about convention as the spec §2.1 (item 2) |
| How-to: Insert Data | "What Not to Insert" | Name the parts of Compute and Ingest tables (item 1) |
| How-to: Master-Part Tables | "When to Use Part Tables" | Same criterion as the spec §7.1 (item 5) |
| Tutorial: Schema Design | "Master-Part (Compositional Integrity)" | "Inserted and deleted as an atomic unit" holds for Entry masters only after item 2 |
Tier renames on these pages follow #1546.
Order: the insert guard for computed parts first, the transaction rule for Entry masters last
- Item 1: one property and one test, released with a warning.
- #1728, then #1620. The schema-name fix (#1719) and item 3's warning ship with them.
- Item 3 raises, and item 4's delete, drop, and cascade call sites move to the ownership rule.
- Item 2: the warning release ships with the rewritten spec §3.1, then the raise. Before it reaches Lookup masters, the parts'
contentsmust be inserted with the master's rows in one transaction (#1772), because decoration commits a Lookup master's rows before its parts are declared. - Item 5 now; it depends on no library change.
- Lenguaje dominante
- Python
- Estrellas
- 198
- Forks
- 107
- Merge medio
- 4 d 7 h
- PR fusionados (30 d)
- 12
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de datajoint/datajoint-python
-
bug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
datajoint/datajoint-python#1775 ·
Los mantenedores suelen responder en 5 días
-
MySQL: with use_tls=False, 2.3.6 needs the cryptography package to log in to MySQL 8Posiblemente ocupada @dimitri-yatsenko la tomó hace 5 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
datajoint/datajoint-python#1750 ·
Los mantenedores suelen responder en 5 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1747 ·
Los mantenedores suelen responder en 5 días
-
Reject constant defaults on primary-key attributesPosiblemente ocupada @godara-alt la tomó hace 4 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
datajoint/datajoint-python#1712 ·
Los mantenedores suelen responder en 5 días
-
Decoding a <blob> value in an unknown format returns None instead of raising an errorPosiblemente ocupada @godara-alt la tomó hace 9 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
datajoint/datajoint-python#1703 ·
Los mantenedores suelen responder en 5 días
Todos los issues de datajoint/datajoint-python
Issues similares
-
[Bug]: test_remote_realpath_uses_argument_vector fails on Windows with Python 3.13+ (ntpath.isabs)Posiblemente ocupada @gouyu-hou la tomó hoy. Abiertotriage/confirmed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
agentscope-ai/agentscope#4397 ·
Los mantenedores suelen responder en 2 días
-
area/profiles area/sessions comp/desktop desktop/chat desktop/sessions P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
NousResearch/hermes-agent#161712 ·
Los mantenedores suelen responder en 1 día
-
[New Check]: postgresql_flexible_server_public_network_access_disabledPosiblemente ocupada @pouria-l la tomó hoy. Abiertofeature-request status/needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
prowler-cloud/prowler#13615 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
SACGF/variantgrid#2941 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
linkedin/Liger-Kernel#1730 ·
Los mantenedores suelen responder en 3 días