Error while trying to run the Python binding (aka Dazl) Hello world example

I’m trying to run this example: dazl-client/samples/hello-world/src at main · digital-asset/dazl-client · GitHub

I’ve made some changes reacting to error messages and to allocate the ledger party with a Daml Script, now this is the Daml file:

module Sample where
import Daml.Script


template Setup
  with
    party: Party
  where
    signatory party
    controller party can
      Execute : ContractId HelloRole
        do
          cidRole <- lookupByKey @HelloRole party
          case cidRole of
            Some cid -> return cid
            None -> create HelloRole with ..


template HelloRole
  with
    party: Party
  where
    signatory party
    key party : Party
    maintainer key

    controller party can
      nonconsuming SayHello : ContractId HelloMessage
        with
          to : Party
          message: Text
        do
          create HelloMessage with
            sender = party
            recipient = to
            message


template HelloMessage
  with
    sender: Party
    recipient: Party
    message: Text
  where
    signatory sender
    observer recipient

    controller recipient can
      AcceptMessage : ()
        do
          return ()

      RejectMessage : ()
        do
          return ()

setup : Script Party
setup = script do 
  alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice")
  aliceId <- validateUserId "alice"
  createUser (User aliceId (Some alice)) [CanActAs alice]
  return alice

And this is the Python file:

#!/usr/bin/env python3

import json
import os
import dazl
from dotenv import load_dotenv
load_dotenv()


def main():
    party = os.getenv('DAML_LEDGER_PARTY')
    url = os.getenv('DAML_LEDGER_URL')
    print(f'Starting a ledger for party {party!r} on {url}...')

    network = dazl.Network()
    network.set_config(url=url)
    client = network.aio_party(party)

    @client.ledger_ready()
    def ensure_setup(event):
        return dazl.create_and_exercise('Sample:Setup', {'party': client.party}, 'Execute', {})

    @client.ledger_created('Sample:HelloMessage')
    def on_message(event):
        if (event.cdata['recipient'] == client.party) and (event.cdata['sender'] != client.party):
            return dazl.exercise_by_key('Sample:HelloRole', client.party, 'SayHello', {
                'to': event.cdata['sender'],
                'message': f'Thank you for telling me, {json.dumps(event.cdata["message"])}'
            })

    network.run_forever()


if __name__ == '__main__':
    main()

And this is the error message I get:

Starting a ledger for party 'Alice::122072b3dd5b69e438b623e11e5854e3dc75b26a62255c7dde609fd15b79bab4278e' on localhost:6865...
The main monitoring thread died.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/dazl/protocols/autodetect.py", line 182, in _main
    for i, metadata in enumerate(_monitor_ledger_network(conn)):
  File "/usr/local/lib/python3.9/site-packages/dazl/protocols/v1/grpc.py", line 270, in grpc_main_thread
    grpc_package_sync(package_provider, store)
  File "/usr/local/lib/python3.9/site-packages/dazl/protocols/v1/grpc.py", line 372, in grpc_package_sync
    m = parse_daml_metadata_pb(package_id, archive_bytes)
  File "/usr/local/lib/python3.9/site-packages/dazl/protocols/v1/pb_parse_metadata.py", line 256, in parse_daml_metadata_pb
    return _parse_daml_metadata_pb(Archive(package_id, package))
  File "/usr/local/lib/python3.9/site-packages/dazl/protocols/v1/pb_parse_metadata.py", line 273, in _parse_daml_metadata_pb
    psb.add_value(vt, vv.expr)
  File "/usr/local/lib/python3.9/site-packages/dazl/damlast/daml_lf_1.py", line 2238, in expr
    expr = self._expr_fn()  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/dazl/damlast/pb_parse.py", line 694, in <lambda>
    expr=lambda: self.parse_Expr(pb.expr),
  File "/usr/local/lib/python3.9/site-packages/dazl/damlast/pb_parse.py", line 264, in parse_Expr
    args["abs"] = self.parse_Expr_Abs(pb.abs)
  File "/usr/local/lib/python3.9/site-packages/dazl/damlast/pb_parse.py", line 368, in parse_Expr_Abs
    self.parse_Expr(pb.body),
  File "/usr/local/lib/python3.9/site-packages/dazl/damlast/pb_parse.py", line 276, in parse_Expr
    args["update"] = self.parse_Update(pb.update)
  File "/usr/local/lib/python3.9/site-packages/dazl/damlast/pb_parse.py", line 483, in parse_Update
    return Update(exercise_by_key=self.parse_Update_ExerciseByKey(pb.exercise_by_key))
  File "/usr/local/lib/python3.9/site-packages/dazl/damlast/pb_parse.py", line 515, in parse_Update_ExerciseByKey
    choice=pb.choice,
AttributeError: choice
The above error was propagated as an initialization error.

Am I doing something wrong, or some changes happened in the Python binding which is not reflected in the example?

I know that there is the new connect API which works better, but I now need the old Network API.

Thanks for reporting! This was, indeed, a bug in dazl itself and has been fixed in 7.8.3. Something about your Daml model triggered this, and dazl is merely crashing on trying to read packages from the ledger.

Please try this version and let me know if it fixes the problem you were encountering!

Thank you David, it works fine now.