Commit 86b1ae7
committed
feat(#1424): self.upstream property for pre-restricted ancestor access
Implements T2.2.b of the provenance trinity. Inside make(), self.upstream
exposes a pre-constructed Diagram.trace(self & key) so users can read
declared ancestors with provenance-safe, ergonomic syntax.
Branch stacked on feat/1423-diagram-trace (#1471) for Diagram.trace().
What's added:
- src/datajoint/autopopulate.py:
- AutoPopulate._upstream class attribute (default None) — instance
storage for the per-make() trace.
- AutoPopulate.upstream property — returns the trace if set, raises
DataJointError with a clear "only available inside make()" message
otherwise. The error includes the fallback pattern
(dj.Diagram.trace(self & key)) so the user knows the escape hatch.
- In _populate_one, set self._upstream = Diagram.trace(self & dict(key))
immediately before the make() invocation block. Construction is
lazy at this layer (graph copy only); the SQL fetch fires when the
user accesses self.upstream[T].fetch(...).
- The existing `finally` block (line 716) that resets _allow_insert
now also resets _upstream to None, so subsequent attribute access
raises a clear error rather than silently returning a stale trace
from the previous make() call.
What's not changed:
- make() signature: unchanged — key remains a dict, make_kwargs work
as before. self.upstream is a new attribute on self, not a new
parameter.
- Tripartite make pattern: self._upstream is set once before all three
make() invocations, so all three phases see the same upstream view.
Tests in tests/integration/test_autopopulate.py (5 new):
- test_upstream_provides_pre_restricted_ancestor — basic case: make()
reads self.upstream[Subject].fetch1("name") and the value is correctly
pre-restricted to the current key.
- test_upstream_rejects_non_ancestor — self.upstream[Unrelated] raises
DataJointError ("not in this trace"). Inherited from Diagram.__getitem__.
- test_upstream_unset_outside_make — accessing the property outside of
make() raises with the helpful "only available inside make()" message.
- test_upstream_cleared_after_make — after populate() completes, accessing
the property on a fresh instance still raises (verifies the finally
cleanup; no stale state).
- test_upstream_seen_across_tripartite_make — both make_fetch / make_compute
/ make_insert see the same self.upstream value.
Full regression: 17/17 autopopulate tests pass on MySQL.
Slated for DataJoint 2.3. Blocked on #1471 (Diagram.trace) merging;
T2.2.c (strict_provenance) is stacked on this PR.1 parent 8d9d242 commit 86b1ae7
2 files changed
Lines changed: 220 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
92 | 132 | | |
93 | 133 | | |
94 | 134 | | |
| |||
611 | 651 | | |
612 | 652 | | |
613 | 653 | | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
614 | 661 | | |
615 | 662 | | |
616 | 663 | | |
| |||
668 | 715 | | |
669 | 716 | | |
670 | 717 | | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
671 | 722 | | |
672 | 723 | | |
673 | 724 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
357 | 526 | | |
358 | 527 | | |
359 | 528 | | |
| |||
0 commit comments