Skip to content

Commit

Permalink
Resetting DependOnIds in BaseSaveResult and ObjectMaterializerLog. Fi…
Browse files Browse the repository at this point in the history
…xing when to add DependsOnIds. Add DependOnIds to missing code paths. Fixes OData#3150
  • Loading branch information
uffelauesen committed Dec 19, 2024
1 parent 70eef8a commit 7be106d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Microsoft.OData.Client/BaseSaveResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ private static void HandleResponsePost(LinkDescriptor linkDescriptor)
Error.ThrowBatchUnexpectedContent(InternalError.LinkNotAddedState);
}

linkDescriptor.DependsOnIds = null;
linkDescriptor.State = EntityStates.Unchanged;
}

Expand Down Expand Up @@ -1226,6 +1227,7 @@ private void HandleResponsePost(EntityDescriptor entityDescriptor, string etag)
{
entityDescriptor.ETag = etag;
entityDescriptor.State = EntityStates.Unchanged;
entityDescriptor.DependsOnIds = null;
entityDescriptor.PropertiesToSerialize.Clear();
}

Expand Down Expand Up @@ -1297,6 +1299,7 @@ private void HandleResponsePut(Descriptor descriptor, HeaderCollection responseH
Debug.Assert(entityDescriptor.State == EntityStates.Modified, "descriptor.State == EntityStates.Modified");
entityDescriptor.ETag = etag;
entityDescriptor.State = EntityStates.Unchanged;
entityDescriptor.DependsOnIds = null;
entityDescriptor.PropertiesToSerialize.Clear();
}
}
Expand All @@ -1306,6 +1309,7 @@ private void HandleResponsePut(Descriptor descriptor, HeaderCollection responseH
if ((EntityStates.Added == descriptor.State) || (EntityStates.Modified == descriptor.State))
{
descriptor.State = EntityStates.Unchanged;
descriptor.DependsOnIds = null;
}
else if (EntityStates.Detached != descriptor.State)
{ // this link may have been previously detached by a detaching entity
Expand All @@ -1317,6 +1321,7 @@ private void HandleResponsePut(Descriptor descriptor, HeaderCollection responseH
Debug.Assert(descriptor.DescriptorKind == DescriptorKind.NamedStream, "it must be named stream");
Debug.Assert(descriptor.State == EntityStates.Modified, "named stream must only be in modified state");
descriptor.State = EntityStates.Unchanged;
descriptor.DependsOnIds = null;

StreamDescriptor streamDescriptor = (StreamDescriptor)descriptor;

Expand Down
20 changes: 17 additions & 3 deletions src/Microsoft.OData.Client/DataServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,11 @@ public virtual void SetLink(object source, string sourceProperty, object target)
if (relation == null)
{
relation = new LinkDescriptor(source, sourceProperty, target, this.model);
EntityDescriptor sourceResource = this.entityTracker.GetEntityDescriptor(source);
if (sourceResource.State == EntityStates.Added)
{
relation.DependsOnIds = new List<string> { sourceResource.ChangeOrder.ToString(CultureInfo.InvariantCulture) };
}
this.entityTracker.AddLink(relation);
}

Expand Down Expand Up @@ -2633,10 +2638,14 @@ public virtual void AddRelatedObject(object source, string sourceProperty, objec
var targetResource = new EntityDescriptor(this.model)
{
Entity = target,
State = EntityStates.Added,
DependsOnIds = new List<string> { sourceResource.ChangeOrder.ToString(CultureInfo.InvariantCulture) }
State = EntityStates.Added
};

if (sourceResource.State == EntityStates.Added)
{
targetResource.DependsOnIds = new List<string> { sourceResource.ChangeOrder.ToString(CultureInfo.InvariantCulture) };
}

targetResource.SetParentForInsert(sourceResource, sourceProperty);

this.EntityTracker.AddEntityDescriptor(targetResource);
Expand Down Expand Up @@ -2884,8 +2893,12 @@ public virtual void UpdateRelatedObject(object source, string sourceProperty, ob
{
Entity = target,
State = EntityStates.Modified,
EditLink = sourceResource.GetNestedResourceInfo(this.baseUriResolver, property)
EditLink = sourceResource.GetNestedResourceInfo(this.baseUriResolver, property)
};
if (sourceResource.State == EntityStates.Added)
{
targetResource.DependsOnIds = new List<string> { sourceResource.ChangeOrder.ToString(CultureInfo.InvariantCulture) };
}

targetResource.SetParentForUpdate(sourceResource, sourceProperty);
this.EntityTracker.AddEntityDescriptor(targetResource);
Expand Down Expand Up @@ -4313,6 +4326,7 @@ private void SetStateToUnchanged(object entity)
}

descriptor.State = EntityStates.Unchanged;
descriptor.DependsOnIds = null;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.OData.Client/ObjectMaterializerLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ internal void ApplyToContext()
{
// we should always reset descriptor's state to Unchanged (old v1 behavior)
descriptor.State = EntityStates.Unchanged;
descriptor.DependsOnIds = null;
descriptor.PropertiesToSerialize.Clear();
}
}
Expand Down

0 comments on commit 7be106d

Please sign in to comment.