Title: Implement Diagram.trace() for upstream restriction propagation · Issue #1423 · datajoint/datajoint-python · GitHub
Open Graph Title: Implement Diagram.trace() for upstream restriction propagation · Issue #1423 · datajoint/datajoint-python
X Title: Implement Diagram.trace() for upstream restriction propagation · Issue #1423 · datajoint/datajoint-python
Description: Summary Implement Diagram.trace(table_expr) as the upstream mirror of Diagram.cascade() — walking the FK graph upward from a restricted table expression, propagating the key restriction through every ancestor with OR convergence. Context...
Open Graph Description: Summary Implement Diagram.trace(table_expr) as the upstream mirror of Diagram.cascade() — walking the FK graph upward from a restricted table expression, propagating the key restriction through eve...
X Description: Summary Implement Diagram.trace(table_expr) as the upstream mirror of Diagram.cascade() — walking the FK graph upward from a restricted table expression, propagating the key restriction through eve...
Opengraph URL: https://github.com/datajoint/datajoint-python/issues/1423
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Implement Diagram.trace() for upstream restriction propagation","articleBody":"## Summary\n\nImplement `Diagram.trace(table_expr)` as the upstream mirror of `Diagram.cascade()` — walking the FK graph **upward** from a restricted table expression, propagating the key restriction through every ancestor with OR convergence.\n\n## Context\n\nDiscussion: #1232\nRelated: #242 (farfetch), PR #1407 (graph-driven cascade)\n\nPR #1407 delivered downstream graph operations (`Diagram.cascade()` and `Diagram.restrict()`). The upstream direction is missing — users cannot programmatically walk the FK graph upward to find which ancestor entities contributed to a given result.\n\n## Design\n\n`Diagram.trace(table_expr)` constructs a restricted upstream diagram:\n\n```python\ntrace = dj.Diagram.trace(MyChild \u0026 key)\ntrace.counts() # entity counts per ancestor table\ntrace[Session] # pre-restricted Session QueryExpression\ntrace[Session].fetch1(\"session_date\")\ntrace[ExtractTraces].to_arrays(\"trace\")\n```\n\n- **Direction**: upstream (child → ancestors)\n- **Convergence**: OR — an ancestor entity is included if reachable through *any* FK path\n- **`trace[TableClass]`**: returns the ancestor table pre-restricted through the FK join path\n- **`trace.counts()`**: entity counts per ancestor table\n- **`trace.heading()`**: all attributes across ancestor tables, grouped by table\n\n### Convergence rules\n\n| Method | Direction | Convergence | Question |\n|--------|-----------|------------|----------|\n| `cascade` | downstream | OR | What's affected if this is deleted? |\n| `restrict` | downstream | AND | What satisfies all these conditions? |\n| `trace` | upstream | OR | What contributed to this result? |\n\n### Restriction propagation (inverse of cascade)\n\nFor edge Parent→Child with `attr_map`, trace reverses the propagation: project child FK values back onto parent primary keys.\n\n## Implementation notes\n\n- Reuses existing Diagram infrastructure: dependency graph, attr_map handling, topological ordering, cross-schema discovery from #1407\n- `trace[TableClass]` via `__getitem__` — only table classes accepted\n- Returns standard `QueryExpression` objects — all existing query operators (join, aggr, proj, restrict) and fetch methods work unchanged","author":{"url":"https://github.com/dimitri-yatsenko","@type":"Person","name":"dimitri-yatsenko"},"datePublished":"2026-04-04T00:49:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1423/datajoint-python/issues/1423"}
| 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:b5107935-3e86-4d4a-e6e1-ce9adeb5ce6a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E820:1FFDFF:175C2C6:1FDF9C6:6A4F0EC9 |
| html-safe-nonce | 01cafed577f1748093fd37a99c72bf203d14bc237cf1ff0fcc59130e8fde061d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODIwOjFGRkRGRjoxNzVDMkM2OjFGREY5QzY6NkE0RjBFQzkiLCJ2aXNpdG9yX2lkIjoiNjQxNDExNTY1MDY2NzQ4MjgyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aca0ff3784455a351f6acba82ac735a0f6262909964f22f506f4337d902d2d3b |
| hovercard-subject-tag | issue:4202807187 |
| 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/1423/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d7a69cfe8e69e73553d94a80db09ddac5f961711162f8f44ffc01a6316ab2dbe/datajoint/datajoint-python/issues/1423 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d7a69cfe8e69e73553d94a80db09ddac5f961711162f8f44ffc01a6316ab2dbe/datajoint/datajoint-python/issues/1423 |
| og:image:alt | Summary Implement Diagram.trace(table_expr) as the upstream mirror of Diagram.cascade() — walking the FK graph upward from a restricted table expression, propagating the key restriction through eve... |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width