Title: Cascade may fail when Part table references another Part with renamed foreign keys · Issue #1429 · datajoint/datajoint-python · GitHub
Open Graph Title: Cascade may fail when Part table references another Part with renamed foreign keys · Issue #1429 · datajoint/datajoint-python
X Title: Cascade may fail when Part table references another Part with renamed foreign keys · Issue #1429 · datajoint/datajoint-python
Description: Summary Diagram.cascade() with part_integrity="cascade" may not correctly propagate restrictions when a Part table references another Part table instead of its Master directly, especially with renamed (projected) foreign keys. Context Di...
Open Graph Description: Summary Diagram.cascade() with part_integrity="cascade" may not correctly propagate restrictions when a Part table references another Part table instead of its Master directly, especially with rena...
X Description: Summary Diagram.cascade() with part_integrity="cascade" may not correctly propagate restrictions when a Part table references another Part table instead of its Master directly, especially...
Opengraph URL: https://github.com/datajoint/datajoint-python/issues/1429
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cascade may fail when Part table references another Part with renamed foreign keys","articleBody":"## Summary\n\n`Diagram.cascade()` with `part_integrity=\"cascade\"` may not correctly propagate restrictions when a Part table references another Part table instead of its Master directly, especially with renamed (projected) foreign keys.\n\n## Context\n\nDiscussion: #1232 (Spyglass Merge table pattern)\nRelated: #1423 (`Diagram.trace()` — same issue applies in the upstream direction)\n\n## Problem\n\nThe Part→Master upward propagation in `_propagate_restrictions()` (diagram.py lines 514-537) does two things:\n\n1. **Identifies the Master** via `extract_master(target)` — uses the `__` naming convention to derive the master table name from the part table name\n2. **Restricts the Master** via `master_ft.proj() \u0026 child_ft.proj()` — joins on shared primary key attributes\n\nThis assumes the Part table shares primary key attributes directly with its Master.\n\n### Case 1: Part references another Part with renamed FK (no direct Master reference)\n\n```python\n@schema\nclass Master(dj.Manual):\n definition = \"\"\"\n master_id : smallint\n \"\"\"\n\n class PartA(dj.Part):\n definition = \"\"\"\n -\u003e master\n part_a_id : smallint\n \"\"\"\n\n class PartB(dj.Part):\n definition = \"\"\"\n -\u003e Master.PartA.proj(src_master='master_id', src_part='part_a_id')\n part_b_id : smallint\n \"\"\"\n```\n\nPartB has no direct FK to Master — it references PartA with renamed keys (`src_master` ← `master_id`, `src_part` ← `part_a_id`). When cascade reaches PartB:\n- `extract_master` correctly identifies Master by naming convention\n- But `master_ft.proj() \u0026 child_ft.proj()` joins on shared attribute names — `master_id` is not in PartB (it was renamed to `src_master`), so the join finds no common attributes\n- The intermediate PartA restriction is also skipped\n\n### Case 2: Part references another Part only (no Master reference at all)\n\n```python\n@schema\nclass Master(dj.Manual):\n definition = \"\"\"\n master_id : smallint\n \"\"\"\n\n class PartA(dj.Part):\n definition = \"\"\"\n -\u003e master\n part_a_id : smallint\n \"\"\"\n\n class PartB(dj.Part):\n definition = \"\"\"\n -\u003e Master.PartA\n part_b_id : smallint\n \"\"\"\n```\n\nPartB references PartA directly (inheriting `master_id` and `part_a_id`). The restriction path should be PartB → PartA → Master. The current code jumps from PartB to Master via `proj() \u0026 proj()`. If `master_id` is inherited through PartA, the join may work by coincidence — but PartA's restriction is skipped entirely.\n\n### Case 3: Merge table with renamed reference from a table with different PK\n\n```python\n@schema\nclass Merge(dj.Manual):\n definition = \"\"\"\n merge_id : uuid\n \"\"\"\n\n class Source1(dj.Part):\n definition = \"\"\"\n -\u003e master\n ---\n -\u003e UpstreamPipeline1\n \"\"\"\n\n class Source2(dj.Part):\n definition = \"\"\"\n -\u003e master\n ---\n -\u003e UpstreamPipeline2\n \"\"\"\n\n@schema\nclass Downstream(dj.Computed):\n definition = \"\"\"\n downstream_id : smallint\n ---\n -\u003e Merge\n -\u003e Merge.proj(comparison_src='merge_id')\n \"\"\"\n```\n\nDownstream has its own primary key and two FKs into Merge — one direct, one renamed via `.proj()`. Cascade from Downstream needs to reach Merge's Parts through both FK paths. The Part→Master propagation doesn't account for the renamed FK (`comparison_src` → `merge_id`).\n\n## Expected behavior\n\nCascade should correctly propagate restrictions through Part→Part→Master chains, including cases with renamed foreign keys (via `.proj()`), by following the actual FK path rather than relying on shared attribute names.\n\n## Proposed fix\n\nWhen propagating from a Part to its Master:\n1. If the Part doesn't share PK attributes directly with Master, follow the FK chain through intermediate Part tables\n2. Apply the standard restriction propagation rules (including `attr_map` alias handling from `_apply_propagation_rule`) at each step, rather than a direct `proj() \u0026 proj()` join\n\n## Verification\n\nNeeds test cases covering:\n- PartB references PartA with renamed FK (no direct Master reference) — verify Master is correctly restricted\n- PartB references PartA directly (no Master reference) — verify PartA and Master are both restricted\n- Renamed FK back to same Master via `.proj()` from a table with different PK — verify both paths are traced","author":{"url":"https://github.com/dimitri-yatsenko","@type":"Person","name":"dimitri-yatsenko"},"datePublished":"2026-04-06T20:21:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1429/datajoint-python/issues/1429"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6bafa9da-ff8c-f2c9-2ccc-876a892fff48 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B74A:47423:CB609E:1102263:6A4EFD46 |
| html-safe-nonce | 6809c43960e93a259a5b4b7bfe5cecda9d3f06d188f56ee6e669cd45284b5886 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzRBOjQ3NDIzOkNCNjA5RToxMTAyMjYzOjZBNEVGRDQ2IiwidmlzaXRvcl9pZCI6IjY5NTg1MjMzNjY5ODM1MzE4NDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0058b649315342abf2a4bd0045c62e83ddbdbb7c9b8bf83e2ed83896bbefc3f1 |
| hovercard-subject-tag | issue:4213881275 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/datajoint/datajoint-python/1429/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a30922b4f46e5a6e3be36f76c13f8de1642b7bc8ea9ddd37e06aa54f06372b4d/datajoint/datajoint-python/issues/1429 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a30922b4f46e5a6e3be36f76c13f8de1642b7bc8ea9ddd37e06aa54f06372b4d/datajoint/datajoint-python/issues/1429 |
| og:image:alt | Summary Diagram.cascade() with part_integrity="cascade" may not correctly propagate restrictions when a Part table references another Part table instead of its Master directly, especially with rena... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dimitri-yatsenko |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/datajoint/datajoint-python git https://github.com/datajoint/datajoint-python.git |
| octolytics-dimension-user_id | 2375501 |
| octolytics-dimension-user_login | datajoint |
| octolytics-dimension-repository_id | 5866704 |
| octolytics-dimension-repository_nwo | datajoint/datajoint-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 5866704 |
| octolytics-dimension-repository_network_root_nwo | datajoint/datajoint-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b8f23afb982271f1b22258a94aede67a6b77760 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width