microsoft / microsoft/Power-Fx

Cannot use JSON function on own record types

Open
#2,189 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.4k
Forks
358
Avg merge
10h 34m
Merged PRs (30d)
3

Description

The following unit test fails but it should not.

    public class LazyRecordType : RecordType
    {
        public LazyRecordType()
        {
        }

        public override IEnumerable<string> FieldNames => new string[1] { "SubProperty" };

        public override bool TryGetFieldType(string name, out FormulaType type)
        {
            var subrecord = RecordType.Empty();
            subrecord = subrecord.Add("x", FormulaType.String);

            type = subrecord;
            return true;
        }

        public override bool Equals(object other)
        {
            return true;
        }

        public override int GetHashCode()
        {
            return 1;
        }
    }

    [Fact]
    public void Json_IncludeBinaryData_AllowSideEffects()
    {
        var config = new PowerFxConfig();
        config.EnableJsonFunctions();

        var engine = new RecalcEngine(config);

        var record = RecordType.Empty();
        record = record.Add("Property", new LazyRecordType());

        var formulaParams = RecordType.Empty();
        formulaParams = formulaParams.Add("Var", record);

        var result = engine.Check(
            "JSON(Var)",
            formulaParams);

        Assert.True(result.IsSuccess);
    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Json_IncludeBinaryData_AllowSideEffects test with EnableJsonFunctions, RecalcEngine.Check, and the JSON(Var) expression shown here. Trace why checking a record containing LazyRecordType does not succeed; done means the supplied test passes with result.IsSuccess true.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.