Skip to content

[BUG]: Count cannot be assigned to a value variable #8688

@Poolshark

Description

@Poolshark

What version of Dgraph are you using?

Dgraph Cloud v21.03.0-92-g0c9f60156

Tell us a little more about your go-environment?

No response

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, CPU, OS)?

Tier: 2R
Storage: 32 GB
Dgraph Hosted: Yes
High Availability: No
SLA: 99.5%
Schema Mode: Flexible

This error can also be reproduced on a Shared Cluster (Free Tier) with a minimal schema.

What steps will reproduce the bug?

1. Deploy minimal schema

type Course {
  id: ID!
  title: String!
  chapters: [Chapter!]!
}

type Chapter {
  id: ID!
  title: String!
  sequence: Int
}

2. Perform initial DQL mutation

{
  "set": {
    "dgraph.type": "Course",
    "Course.title": "Course 1",
    "Course.chapters": [
      {
        "dgraph.type": "Chapter",
        "Chapter.title": "Chapter 1",
        "Chapter.sequence": 0
      },
      {
        "dgraph.type": "Chapter",
        "Chapter.title": "Chapter 2",
        "Chapter.sequence": 1
      }
    ]
  } 
}

3. Perform upsert DQL mutation

{
  "query": "{ qTest(func: uid(0x1)) { u as uid c as count(Course.chapters) } }",
  "mutations": [
    {
      "set": {
        "uid": "uid(u)",
        "Course.chapters": [
          {
            "dgraph.type": "Chapter",
            "Chapter.title": "Test Chapter",
            "Chapter.sequence": "val(c)"
          }
        ]
      }
    }
  ]
}
Response
{
  data: {
    code: "Success"
    message: "Done"
    queries: {
      qTest: [
        0: {
          uid:"0x1"
          count(Course.chapters): 2
        }
      ]
    }
    uids: {
      dg.3162278161.22051:"0x1"
    }
}

Expected behavior and actual result.

We would expect that Chapter.sequence of the new Chapter Test Chapter would equal 2 since count(Course.chapters) validates 2.

This behaviour is also documented in the official docs.

Additional information

Chapter.sequence of the newly created Chapter Test Chapter remains undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    communityIssue or PR created by the community.kind/bugSomething is broken.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions