# Facet encoding breaks with loop:false

**URL:** <https://discuss.dgraph.io/t/facet-encoding-breaks-with-loop-false/8799>\
**Category:** Dgraph\
**Tags:** dgraph, status:accepted, kind:bug, priority:p1, area:facets\
**Created:** [October 15, 2019, 12:12am UTC](https://discuss.dgraph.io/t/facet-encoding-breaks-with-loop-false/8799 "2019-10-15T00:12:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [October 15, 2019, 12:12am UTC](https://discuss.dgraph.io/t/facet-encoding-breaks-with-loop-false/8799/1 "2019-10-15T00:12:24Z")

</div>

**Moved from GitHub [dgraph/4168](https://github.com/dgraph-io/dgraph/issues/4168)**

_Posted by_ [campoy](https://github.com/campoy):

### What version of Dgraph are you using?

1.1.0

### Have you tried reproducing the issue with the latest release?

yes

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

n/a

### Steps to reproduce the issue (command/config used to run Dgraph).

Given this fully connected graph:

```auto

{
  set {
    _:a <name> "A" .
    _:b <name> "B" .
    _:c <name> "C" .
    _:d <name> "D" .

    _:a <connects> _:b (number=1) .
    _:a <connects> _:c (number=2) .
    _:a <connects> _:d (number=3) .

    _:c <connects> _:a (number=4) .
    _:c <connects> _:b (number=5) .
    _:c <connects> _:d (number=6) .

    _:b <connects> _:a (number=7) .
    _:b <connects> _:c (number=8) .
    _:b <connects> _:d (number=9) .

    _:d <connects> _:a (number=10) .
    _:d <connects> _:b (number=11) .
    _:d <connects> _:c (number=12) .
  }
}

```

Run the following query (assuming “A” was given uid 0x1)

```auto
{
  dcs(func: uid(0x1)) @recurse(depth: 4, loop:false) {
    dcname
    connects @facets(number)
  }
}

```

### Expected behaviour and actual result.

I would expect to see all of the nodes connected to each other with unique `number` values for their facets. Instead I get this:

```json
{
  "data": {
    "dcs": [
      {
        "connects": [
          {
            "connects": [
              {
                "connects|number": [
                  1,
                  7
                ]
              },
              {
                "connects|number": [
                  4,
                  8
                ]
              },
              {
                "connects|number": [
                  10,
                  9
                ]
              }
            ],
            "connects|number": 1
          },
          {
            "connects": [
              {
                "connects|number": [
                  1,
                  4
                ]
              },
              {
                "connects|number": [
                  7,
                  5
                ]
              },
              {
                "connects|number": [
                  10,
                  6
                ]
              }
            ],
            "connects|number": 2
          },
          {
            "connects": [
              {
                "connects|number": [
                  1,
                  10
                ]
              },
              {
                "connects|number": [
                  7,
                  11
                ]
              },
              {
                "connects|number": [
                  4,
                  12
                ]
              }
            ],
            "connects|number": 3
          }
        ]
      }
    ]
  }
}

```

Note that adding a second facet fixes the issue.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 6, 2020, 2:25am UTC](https://discuss.dgraph.io/t/facet-encoding-breaks-with-loop-false/8799/2 "2020-05-06T02:25:27Z")

</div>

[kesor](https://github.com/kesor) _commented_ :

When a `@recurse` query stops because of `loop:false`, it _DOES_ return the facets but _DOES NOT_ return the predicate that is associated with these facets.

Example:

```auto
{
  set {
    _:a <name> "A" .
    _:a <dgraph.type> "Example" .
    _:b <name> "B" .
    _:b <dgraph.type> "Example" .
    _:a <connects> _:b (number=1) .
    _:b <connects> _:a (number=7) .
  }
}

```

```auto
query {
  example(func:type("Example"))
  @recurse {
    name
    connects @facets
  }
}

```

Notice how `example[0].connects[0]` is missing `connects[]` but has the facets for that predicate!

```auto
{
  "data": {
    "example": [
      {
        "name": "A",
        "connects": [
          {
            "name": "B",
            "connects|number": {
              "0": 7
            }
          }
        ],
        "connects|number": {
          "0": 1
        }
      }

```

On the other hand, when `loop:true` is enabled (with depth) it appears that the bug is not there.

```auto
query {
  example(func:type("Example"))
  @recurse(loop:true,depth:4) {
    name
    connects @facets
  }
}

```

```auto
{
  "data": {
    "example": [
      {
        "name": "A",
        "connects": [
          {
            "name": "B",
            "connects": [
              {
                "name": "A",
                "connects": [
                  {
                    "name": "B"
                  }
                ],
                "connects|number": {
                  "0": 1
                }
              }
            ],
            "connects|number": {
              "0": 7
            }
          }
        ],
        "connects|number": {
          "0": 1
        }
      },

```
