Skip to content

Commit

Permalink
merge: #4018
Browse files Browse the repository at this point in the history
4018: fix(dal): calc prototypes and values correctly on component upgrade r=zacharyhamm a=zacharyhamm

Walk the attribute value tree of the new component and find the values in the old component that match in the new, setting them when appropriate. Also detect if component specific prototypes were configured on the old component, and attempt to configure them here.

Closes BUG-405

Co-authored-by: Zachary Hamm <[email protected]>
  • Loading branch information
si-bors-ng[bot] and zacharyhamm authored Jun 22, 2024
2 parents e9fce9e + d189c7d commit c66e7ca
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 61 deletions.
4 changes: 2 additions & 2 deletions lib/dal-test/src/test_exclusive_schemas/dummy_secret.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dal::func::argument::FuncArgumentKind;
use dal::func::intrinsics::IntrinsicFunc;
use dal::pkg::import_pkg_from_pkg;
use dal::prop::PropPath;
use dal::prop::{PropPath, SECRET_KIND_WIDGET_OPTION_LABEL};
use dal::schema::variant::leaves::LeafKind;
use dal::{BuiltinsResult, DalContext};
use si_pkg::{
Expand Down Expand Up @@ -152,7 +152,7 @@ fn assemble_secret_definition_dummy(
.widget_options(serde_json::json![
[
{
"label": "secretKind",
"label": SECRET_KIND_WIDGET_OPTION_LABEL,
"value": secret_definition_name
}
]
Expand Down
4 changes: 2 additions & 2 deletions lib/dal-test/src/test_exclusive_schemas/fallout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dal::action::prototype::ActionKind;
use dal::pkg::import_pkg_from_pkg;
use dal::prop::PropPath;
use dal::prop::{PropPath, SECRET_KIND_WIDGET_OPTION_LABEL};
use dal::{BuiltinsResult, DalContext, PropKind};
use si_pkg::{
ActionFuncSpec, AttrFuncInputSpec, AttrFuncInputSpecKind, FuncSpec, FuncSpecBackendKind,
Expand Down Expand Up @@ -211,7 +211,7 @@ fn assemble_dummy_secret_socket_and_prop(
.widget_options(serde_json::json![
[
{
"label": "secretKind",
"label": SECRET_KIND_WIDGET_OPTION_LABEL,
"value": secret_definition_name
}
]
Expand Down
10 changes: 10 additions & 0 deletions lib/dal/src/attribute/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::{
OutputSocketId, PropId, SchemaVariant, SchemaVariantError, SchemaVariantId, Timestamp,
TransactionsError,
};
use crate::{Func, FuncError};

pub mod argument;
pub mod debug;
Expand All @@ -54,6 +55,8 @@ pub enum AttributePrototypeError {
ChangeSet(#[from] ChangeSetError),
#[error("edge weight error: {0}")]
EdgeWeight(#[from] EdgeWeightError),
#[error("func error: {0}")]
Func(#[from] FuncError),
#[error("helper error: {0}")]
Helper(#[from] HelperError),
#[error("layer db error: {0}")]
Expand Down Expand Up @@ -184,6 +187,13 @@ impl AttributePrototype {
Err(AttributePrototypeError::MissingFunction(prototype_id))
}

pub async fn func(
ctx: &DalContext,
prototype_id: AttributePrototypeId,
) -> AttributePrototypeResult<Func> {
Ok(Func::get_by_id_or_error(ctx, Self::func_id(ctx, prototype_id).await?).await?)
}

pub async fn find_for_prop(
ctx: &DalContext,
prop_id: PropId,
Expand Down
10 changes: 9 additions & 1 deletion lib/dal/src/attribute/prototype/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ impl AttributePrototypeArgument {
.await
}

pub async fn func_argument(
&self,
ctx: &DalContext,
) -> AttributePrototypeArgumentResult<FuncArgument> {
let func_arg_id = Self::func_argument_id_by_id(ctx, self.id).await?;
Ok(FuncArgument::get_by_id_or_error(ctx, func_arg_id).await?)
}

pub async fn func_argument_id_by_id(
ctx: &DalContext,
apa_id: AttributePrototypeArgumentId,
Expand Down Expand Up @@ -376,7 +384,7 @@ impl AttributePrototypeArgument {
Ok(None)
}

async fn set_value_source(
pub async fn set_value_source(
self,
ctx: &DalContext,
value_id: Ulid,
Expand Down
12 changes: 12 additions & 0 deletions lib/dal/src/attribute/prototype/argument/value_source.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::fmt;

use si_events::ulid::Ulid;
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -66,6 +67,16 @@ impl ValueSource {
})
}

pub fn into_inner_id(self) -> Ulid {
match self {
ValueSource::InputSocket(id) => id.into(),
ValueSource::OutputSocket(id) => id.into(),
ValueSource::Prop(id) => id.into(),
ValueSource::Secret(id) => id.into(),
ValueSource::StaticArgumentValue(id) => id.into(),
}
}

pub async fn attribute_values_for_component_id(
&self,
ctx: &DalContext,
Expand All @@ -92,6 +103,7 @@ impl ValueSource {
Ok(result)
}
}

impl fmt::Display for ValueSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
32 changes: 22 additions & 10 deletions lib/dal/src/attribute/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,7 @@ impl AttributeValue {
ctx: &DalContext,
attribute_value_id: AttributeValueId,
attribute_prototype_id: AttributePrototypeId,
key: Option<String>,
) -> AttributeValueResult<()> {
let maybe_existing_prototype_id =
Self::component_prototype_id(ctx, attribute_value_id).await?;
Expand All @@ -1752,7 +1753,7 @@ impl AttributeValue {
ctx,
attribute_value_id,
attribute_prototype_id,
EdgeWeightKind::Prototype(None),
EdgeWeightKind::Prototype(key),
)
.await?;

Expand Down Expand Up @@ -1786,7 +1787,8 @@ impl AttributeValue {

Ok(())
}
async fn set_value(

pub async fn set_value(
ctx: &DalContext,
attribute_value_id: AttributeValueId,
value: Option<Value>,
Expand Down Expand Up @@ -1831,7 +1833,7 @@ impl AttributeValue {
let func_id = Func::find_intrinsic(ctx, intrinsic_func).await?;
let prototype = AttributePrototype::new(ctx, func_id).await?;

Self::set_component_prototype_id(ctx, attribute_value_id, prototype.id()).await?;
Self::set_component_prototype_id(ctx, attribute_value_id, prototype.id(), None).await?;

let func_args = match normalized_value {
Some(value) => {
Expand Down Expand Up @@ -2274,6 +2276,22 @@ impl AttributeValue {
}
}

/// If the child attribute value is the child of a map, return its map key. Otherwise return None
pub async fn get_key_of_child_entry(
ctx: &DalContext,
parent_attribute_value_id: AttributeValueId,
child_attribute_value_id: AttributeValueId,
) -> AttributeValueResult<Option<String>> {
Ok(ctx
.workspace_snapshot()?
.find_edge(parent_attribute_value_id, child_attribute_value_id)
.await?
.and_then(|weight| match weight.kind() {
EdgeWeightKind::Contain(key) => key.to_owned(),
_ => None,
}))
}

pub async fn get_index_or_key_of_child_entry(
ctx: &DalContext,
child_id: AttributeValueId,
Expand All @@ -2297,14 +2315,8 @@ impl AttributeValue {
None => None,
}
}
PropKind::Map => ctx
.workspace_snapshot()?
.find_edge(pav_id, child_id)
PropKind::Map => Self::get_key_of_child_entry(ctx, pav_id, child_id)
.await?
.and_then(|weight| match weight.kind() {
EdgeWeightKind::Contain(key) => key.to_owned(),
_ => None,
})
.map(KeyOrIndex::Key),
_ => None,
}
Expand Down
Loading

0 comments on commit c66e7ca

Please sign in to comment.