# \`RegisteredTemplates \[ \]\` behaves as \`AllInDar\`

**URL:** <https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789>\
**Category:** App Development\
**Tags:** trigger\
**Created:** [December 14, 2020, 7:11pm UTC](https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789 "2020-12-14T19:11:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Kapolnai](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/richard_kapolnai/32/89_2.png) [@Richard\_Kapolnai](https://forum.canton.network/u/Richard_Kapolnai)\
**Post date:** [December 14, 2020, 7:11pm UTC](https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789/1 "2020-12-14T19:11:35Z")

</div>

Apparently if a trigger specification has `registeredTemplates = RegisteredTemplates []`, it behaves as if `registeredTemplates = AllInDar` was specified. Is this always the case?

MWE:

```haskell
-- Usage:
-- daml start
-- daml trigger --wall-clock-time --dar .daml/dist/*.dar --trigger-name RegisteredTemplates:trigger --ledger-host localhost --ledger-port 6865 --ledger-party Alice

module RegisteredTemplates where

import Daml.Trigger as Trigger
import DA.Foldable (forA_)

template A
  with
    p : Party
  where
    signatory p

template B
  with
    p : Party
  where
    signatory p

trigger: Trigger ()
trigger = Trigger
  { initialize = pure ()
  , updateState = \_ -> pure ()
  , rule = triggerImpl
  , registeredTemplates = RegisteredTemplates [
      -- registeredTemplate @A -- Uncomment this line, then the trigger will not find B, only A
    ]
  , heartbeat = None
  }

triggerImpl: Party -> TriggerA () ()
triggerImpl party = do
  as <- Trigger.query @A
  forA_ as (\(cid, _) -> cid `Trigger.dedupExercise` Archive)
  bs <- Trigger.query @B
  forA_ bs (\(cid, _) -> cid `Trigger.dedupExercise` Archive)

```

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [December 14, 2020, 7:49pm UTC](https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789/2 "2020-12-14T19:49:40Z")

</div>

Good question! This was definitely not intentional. However, ignoring triggers for a minute and looking at the ledger behavior, I am a bit confused:

The docs for the filter are as follows:

```haskell
message Filters {

  // If not set, no filters will be applied.
  // Optional
  InclusiveFilters inclusive = 1;
}

// If no internal fields are set, no data will be returned.
message InclusiveFilters {

  // A collection of templates.
  // SHOULD NOT contain duplicates.
  // Required
  repeated Identifier template_ids = 1;
}

```

However, I tried the following 3 examples and they seem to apply no filtering:

1. No filter, this is fine according to the docs this should apply no filters.

```haskell
grpcurl 
 -d '{"ledger_id": "l", "filter": {"filtersByParty": {"Alice": {}}}, "begin": {"boundary": "LEDGER_BEGIN"}, "end": {"boundary": "LEDGER_END"}}' 
 -plaintext localhost:6865
 com.daml.ledger.api.v1.TransactionService/GetTransactions

```

1. Set `inclusive` with no template ids, this seems wrong to me. I didn’t set any inner fields so I would expect to get back no data but I still get back everything.

```haskell
grpcurl
   -d '{"ledger_id": "l", "filter": {"filtersByParty": {"Alice": {"inclusive": {}}}}, "begin": {"boundary": "LEDGER_BEGIN"}, "end": {"boundary": "LEDGER_END"}}' 
  -plaintext localhost:6865 
  com.daml.ledger.api.v1.TransactionService/GetTransactions

```

1. Just to sanity check, I also tried an empty list of template ids. This should be equivalent to not setting the field in protobuf but 🤷‍♀️

```haskell
grpcurl
  -d '{"ledger_id": "l", "filter": {"filtersByParty": {"Alice": {"inclusive": {"template_ids": []}}}}, "begin": {"boundary": "LEDGER_BEGIN"}, "end": {"boundary": "LEDGER_END"}}'
  -plaintext localhost:6865
  com.daml.ledger.api.v1.TransactionService/GetTransactions

```

So I’m struggling a bit to figure out how you are supposed to send a request that filters out all data.

---

<div class="post-metadata">

**Author:** ![gerolf](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gerolf/32/358_2.png) [@gerolf](https://forum.canton.network/u/gerolf)\
**Post date:** [December 16, 2020, 11:42am UTC](https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789/3 "2020-12-16T11:42:59Z")

</div>

An empty list of inclusive filters is treated the same way as a missing filter definition (see [LedgerBackedIndexService.scala#L156](https://github.com/digital-asset/daml/blob/edae9ddb3369bbbd0a59fa2c3006ae5afaf27220/ledger/participant-integration-api/src/main/scala/platform/index/LedgerBackedIndexService.scala#L156)).

I think it would be sensible to reject a request with an empty inclusive filter with `INVALID_ARGUMENT`.

What’s the use case for sending a request that filters out all data?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [December 16, 2020, 11:48am UTC](https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789/4 "2020-12-16T11:48:21Z")

</div>

@gerolf I don’t have a usecase, I mainly got confused because the docs atm claim `// If no internal fields are set, no data will be returned.`. Updating docs is perfectly fine with me.

---

<div class="post-metadata">

**Author:** ![gerolf](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gerolf/32/358_2.png) [@gerolf](https://forum.canton.network/u/gerolf)\
**Post date:** [December 16, 2020, 1:45pm UTC](https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789/5 "2020-12-16T13:45:59Z")

</div>

Oh, sorry, I missed that bit. Yeah, I think instead of rejecting the request we should rather change the documentation.

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [December 17, 2020, 7:35am UTC](https://forum.canton.network/t/registeredtemplates-behaves-as-allindar/1789/6 "2020-12-17T07:35:44Z")

</div>

The documentation has now been updated to reflect the current behavior.

Going back to the original question, triggers are at least consistent with how filters work on the ledger API and the docs. Maybe still worth emitting a warning if you specify an empty list of registered templates in triggers since it doesn’t seem very useful.
