Commit b977e62
authored
ENG-9350: App.modify_state can directly modify SharedState tokens (#6336)
* ENG-9350: App.modify_state can directly modify SharedState tokens
When a SharedState is modified directly by its shared token (e.g. from an
API route webhook), propagate dirty vars to all clients linked to that
shared state — matching the behavior that already exists when modifying
shared state through a private client token.
- Add _collect_shared_token_updates on SharedStateBaseInternal to detect
the shared-token case inside _modify_linked_states and propagate to
linked clients via the existing _do_update_other_tokens mechanism
- Add App.set_contexts / App._set_contexts_internal to centralize pushing
RegistrationContext and EventContext into the current contextvars scope,
replacing the old _registration_context_middleware
- App.modify_state now calls set_contexts so out-of-band callers (API
routes, webhooks) get the necessary contexts automatically
- Integration test: API endpoint modifies two SharedState subclasses by
shared token, asserts both propagate to two linked browser tabs, and
verifies normal event handlers still work afterward
- Unit tests for set_contexts covering all combinations of pre-existing /
absent contexts, no-event-processor, and reset-on-exit behavior
Closes #6335
* deal with race condition due to slower execution in CI environment
set an initial value for the shared state to provide affirmative proof that the
state was linked _before_ the API call was made.
if only one state was linked when the HTTP request was made, then only one
state would be updated by such request resulting in the observed behavior.
* followup from previous commit
but actually set the value on the newly linked state, not the old private
state. derpy easy to make mistake with this _link_to mechanism =/
* Add test case for fetching previously unfetched linked state
Using BaseState.get_state(...) with a linked state that _is_ linked, but not
currently cached should fetch the linked state instance, not the private state
instance.
* Handle `.get_state` when directly modifying a shared token
In an `app.modify_state(...)` context where the passed token is a shared token,
handle the case where `.get_state(...)` is used to fetch _another_ shared state
with the same token as the original shared state token.
Basically if some code is modifying "tokenA" for "Shared1" and calls
`shared_1.get_state(Shared2)`, then the retrieved state will also be associated
with "tokenA", as expected.
* recursively _collect_shared_token_updates
Starting from the SharedStateBaseInternal, recurse into each pre-cached
instance and collect affected tokens and dirty vars.
* Fixturify the new test_app set_contexts test case
* remove superfluous `run_isolated` fixture
just use `isolated_context.run` for simplicity1 parent 3bc86bb commit b977e62
5 files changed
Lines changed: 491 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| 45 | + | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| |||
577 | 580 | | |
578 | 581 | | |
579 | 582 | | |
580 | | - | |
581 | | - | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
582 | 642 | | |
583 | 643 | | |
584 | 644 | | |
| |||
587 | 647 | | |
588 | 648 | | |
589 | 649 | | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
| 650 | + | |
| 651 | + | |
595 | 652 | | |
596 | 653 | | |
597 | | - | |
| 654 | + | |
598 | 655 | | |
599 | 656 | | |
600 | 657 | | |
| |||
672 | 729 | | |
673 | 730 | | |
674 | 731 | | |
675 | | - | |
| 732 | + | |
676 | 733 | | |
677 | 734 | | |
678 | | - | |
| 735 | + | |
679 | 736 | | |
680 | 737 | | |
681 | 738 | | |
| |||
1615 | 1672 | | |
1616 | 1673 | | |
1617 | 1674 | | |
1618 | | - | |
1619 | | - | |
1620 | | - | |
1621 | | - | |
1622 | | - | |
1623 | | - | |
1624 | | - | |
1625 | | - | |
1626 | | - | |
1627 | | - | |
1628 | | - | |
1629 | | - | |
1630 | | - | |
1631 | | - | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
1632 | 1691 | | |
1633 | 1692 | | |
1634 | 1693 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
176 | 208 | | |
177 | 209 | | |
178 | 210 | | |
| |||
194 | 226 | | |
195 | 227 | | |
196 | 228 | | |
197 | | - | |
| 229 | + | |
198 | 230 | | |
199 | 231 | | |
200 | 232 | | |
| |||
280 | 312 | | |
281 | 313 | | |
282 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
283 | 327 | | |
284 | 328 | | |
285 | 329 | | |
| |||
386 | 430 | | |
387 | 431 | | |
388 | 432 | | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
389 | 449 | | |
390 | 450 | | |
391 | 451 | | |
| |||
397 | 457 | | |
398 | 458 | | |
399 | 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 | + | |
400 | 488 | | |
401 | 489 | | |
402 | 490 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2146 | 2146 | | |
2147 | 2147 | | |
2148 | 2148 | | |
2149 | | - | |
2150 | 2149 | | |
2151 | 2150 | | |
2152 | 2151 | | |
| |||
2155 | 2154 | | |
2156 | 2155 | | |
2157 | 2156 | | |
2158 | | - | |
2159 | | - | |
2160 | | - | |
2161 | | - | |
2162 | | - | |
2163 | | - | |
2164 | 2157 | | |
2165 | | - | |
2166 | | - | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
2167 | 2163 | | |
2168 | 2164 | | |
2169 | 2165 | | |
| |||
0 commit comments