Fixes reuse of expandinfo from cache when expand is accessed via a different path (#2580)

Unable to easily test in this repo. Tests added in PA Client. 

Scenario is, e.g. for this expression, the expand info to the second
PrimaryContact access should have ManagingPartner as part of it's expand
path.

"ClearCollect(c3, Filter(Accounts,'Primary Contact'.Status <> 'Status
(Contacts)'.Active));" +
"ClearCollect(c4, Filter(Contacts, 'Managing Partner'.'Primary
Contact'.Status <> 'Status (Contacts)'.Inactive))"
This commit is contained in:
McCall Saltzman 2024-08-06 11:41:40 -07:00 коммит произвёл GitHub
Родитель 75a9c04000
Коммит 59aa6c1a63
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -3836,6 +3836,16 @@ namespace Microsoft.PowerFx.Core.Binding
// Update the datasource and relatedEntity path.
type.ExpandInfo.UpdateEntityInfo(expandEntityInfo.ParentDataSource, relatedEntityPath);
entityTypes.Add(expandEntityInfo.ExpandPath, type);
}
else if (!type.ExpandInfo.ExpandPath.IsReachedFromPath(relatedEntityPath))
{
// Expands reached via a different path should have a different relatedentitypath.
// If we found an expand in the cache but it's not accessed via the same relationship
// we need to create a different expand info but with the same type.
// DType.Clone doesn't clone expand info, so we force that with CopyExpandInfo,
// because that sadly mutates expand info on what should otherwise be an immutable dtype.
type = DType.CopyExpandInfo(type.Clone(), type);
type.ExpandInfo.UpdateEntityInfo(expandEntityInfo.ParentDataSource, relatedEntityPath);
}
return type;

Просмотреть файл

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using Microsoft.PowerFx.Core.Utils;
namespace Microsoft.PowerFx.Core.Types
@ -34,6 +35,11 @@ namespace Microsoft.PowerFx.Core.Types
public static bool operator !=(ExpandPath lhsPath, ExpandPath rhsPath) => lhsPath.ToString() != rhsPath.ToString();
public bool IsReachedFromPath(string relatedEntityPath)
{
return relatedEntityPath?.TrimEnd(PathSeperator) == RelatedEntityPath;
}
public bool Equals(ExpandPath path)
{
return this == path;