Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit 739c193

Browse files
author
Zachary Hamm
committed
feat(dal): enable subscription cycle check with whitelist
1 parent d751ab5 commit 739c193

4 files changed

Lines changed: 63 additions & 13 deletions

File tree

‎lib/dal-test/src/helpers/attribute/value.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ pub async fn subscribe(
4545
Ok(())
4646
}
4747

48+
/// Set the subs on a value, without doing sanity checks
49+
pub async fn subscribe_unchecked(
50+
ctx: &DalContext,
51+
subscriber: impl AttributeValueKey,
52+
subscription: impl AttributeValueKey,
53+
) -> Result<()> {
54+
let subscriber = vivify(ctx, subscriber).await?;
55+
let subscription = AttributeValueKey::to_subscription(ctx, subscription).await?;
56+
let reason = Reason::new_user_added(ctx);
57+
AttributeValue::set_to_subscription_unchecked(ctx, subscriber, subscription, None, reason)
58+
.await?;
59+
Ok(())
60+
}
61+
4862
/// Set the subscriptions on a value
4963
pub async fn subscribe_with_custom_function(
5064
ctx: &DalContext,

‎lib/dal/src/attribute/value.rs‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ use crate::{
7373
TransactionsError,
7474
attribute::prototype::AttributePrototypeError,
7575
change_set::ChangeSetError,
76+
component::subscription_graph::sub_cycle_check,
7677
func::{
7778
FuncExecutionPk,
7879
argument::{
@@ -1964,17 +1965,14 @@ impl AttributeValue {
19641965
Self::set_to_subscription_unchecked(ctx, subscriber_av_id, subscription, func_id, reason)
19651966
.await?;
19661967

1967-
Ok(())
1968-
1969-
// When we are sure there are no subscription cycles in the wild, uncomment this
1970-
// if SubscriptionGraph::new(ctx).await?.is_cyclic() {
1971-
// Err(AttributeValueError::SubscriptionWouldCycle {
1972-
// subscriber_av_id,
1973-
// subscription: subscription_title,
1974-
// })
1975-
// } else {
1976-
// Ok(())
1977-
// }
1968+
if sub_cycle_check(ctx).await? {
1969+
Err(AttributeValueError::SubscriptionWouldCycle {
1970+
subscriber_av_id,
1971+
subscription: subscription_title,
1972+
})
1973+
} else {
1974+
Ok(())
1975+
}
19781976
}
19791977

19801978
/// Set the source of this attribute value to one or more subscriptions.

‎lib/dal/src/component/subscription_graph.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,29 @@ impl SubscriptionGraph {
180180
&self.inner
181181
}
182182
}
183+
184+
const WHITELISTED_WORKSPACES: [&str; 8] = [
185+
"01J8K1NADNB211F3PGW0WVFNGZ",
186+
"01K6BVSETG8RWWFA9XAJ466DJH",
187+
"01K6ZNY9ZBKR7KZ2BGZYF6HNJS",
188+
"01K8KS1SMGNZ1YHEVN4YCPWRSM",
189+
"01K9D7ZN09EBNPBSSMVFG3NVTZ",
190+
"01KAE9XXM3FCFFN44E8C8XTMN1",
191+
"01KAEX523JDZ2H335FR853X684",
192+
"01KC00WFPBNZNMMYCE367JR98C",
193+
];
194+
195+
/// Check if the current workspace snapshot has a subscription cycle,
196+
/// but ignore whitelisted workspaces
197+
pub async fn sub_cycle_check(ctx: &DalContext) -> ComponentResult<bool> {
198+
let workspace_id = ctx.workspace_pk()?;
199+
let workspace_id_str = workspace_id.to_string();
200+
201+
Ok(
202+
if WHITELISTED_WORKSPACES.contains(&workspace_id_str.as_str()) {
203+
false
204+
} else {
205+
SubscriptionGraph::new(ctx).await?.is_cyclic()
206+
},
207+
)
208+
}

‎lib/dal/tests/integration_test/attribute_value/subscription.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,19 @@ async fn subscription_cycles(ctx: &mut DalContext) -> Result<()> {
777777

778778
assert!(issues.is_empty());
779779

780-
value::subscribe(
780+
// This should produce a cycle (and an error)
781+
assert!(
782+
value::subscribe(
783+
ctx,
784+
("source_2", "/domain/Value2"),
785+
("subscriber", "/domain/Value2"),
786+
)
787+
.await
788+
.is_err()
789+
);
790+
791+
// Create the cycle by skipping checks
792+
value::subscribe_unchecked(
781793
ctx,
782794
("source_2", "/domain/Value2"),
783795
("subscriber", "/domain/Value2"),
@@ -879,7 +891,7 @@ async fn subscription_graph_constructors_produce_identical_results(
879891
)
880892
.await?;
881893

882-
value::subscribe(
894+
value::subscribe_unchecked(
883895
ctx,
884896
("subscriber2", "/domain/Value2"),
885897
("source2", "/domain/Value"),

0 commit comments

Comments
 (0)