Key containing Decimal not returning contract
- RyanMedlenOP
We are using the fetch endpoint in the json api to pull a contract by the key. It seems like when the key contains a record it doesn’t work . Below is the relevant parts. Is there a different way to pass a record in the query?
This works
"_4": { "gender": "Female", "riskClass": "EliteNonTobacco", "state": null, "coverageBand": null }This doesn’t
"_4": { "gender": "Female", "riskClass": "SubstandardTobacco", "state": null, "coverageBand": { "min": "900000.0", "max": null } }Both match a key exactly as it shows in DAML hub on the contract. Thanks.
- RyanMedlen
We did some more testing and it doesn’t seem like its the “coverageBand” that is the issue. It looks like its a issue with the decimal as we did a test contract with a key of a simple decimal and it still didn’t work so looking like its a bug with retrieving keys that are decimals.
- gyorgybalazsi
It seems that there is a bug either on Daml Hub or in the JSON API in general, which causes the below problem when we have a decimal in the contract key and try to fetch the contract from Daml Hub. A query containing the same decimal works correctly.
With this simple contract, containing a simple decimal as key:
type AssetId = ContractId Asset type Amount = Numeric 6 template Asset with issuer : Party owner : Party name : Text amount : Amount where ensure name /= "" signatory issuer key (issuer, amount): (Party, Amount) maintainer key._1 observer owner choice Give : AssetId with newOwner : Party controller owner do create this with owner = newOwneron the ledger
{ "agreementText": "", "contractId": "00da59a856ea12917b203a860b54bfbddbbfff8107b846fcd913490be00778821cca01122092d960b0a202a533c82a2883b78cca42d4a5d00a487cc5c9f2c419871e34e1f2", "key": { "_1": "ledger-party-28949341-d92b-431e-a837-76270fc1de7e::12207d012e8c20f05382642834ca2025bf06d5b647b364187966e26eb6921dc678f3", "_2": "300000.0" }, "observers": [], "payload": { "issuer": "ledger-party-28949341-d92b-431e-a837-76270fc1de7e::12207d012e8c20f05382642834ca2025bf06d5b647b364187966e26eb6921dc678f3", "owner": "ledger-party-28949341-d92b-431e-a837-76270fc1de7e::12207d012e8c20f05382642834ca2025bf06d5b647b364187966e26eb6921dc678f3", "name": "TV", "amount": "300000.0" }, "signatories": [ "ledger-party-28949341-d92b-431e-a837-76270fc1de7e::12207d012e8c20f05382642834ca2025bf06d5b647b364187966e26eb6921dc678f3" ], "templateId": "a4dfe7d506543faf6776f44b6ce9e87725e5d1beb0ab135e9c55d453b06ce21b:Main:Asset" }for this fetch request:
{ "templateId": "a4dfe7d506543faf6776f44b6ce9e87725e5d1beb0ab135e9c55d453b06ce21b:Main:Asset", "key": { "_1": "ledger-party-28949341-d92b-431e-a837-76270fc1de7e::12207d012e8c20f05382642834ca2025bf06d5b647b364187966e26eb6921dc678f3", "_2": "300000.0" } }I also get the null response:
{ "result": null, "status": 200 }So it may be the case that the decimal in the key causes the problem, which seems to be a bug.
The query, containing the same decimal works:
{ "templateIds": ["a4dfe7d506543faf6776f44b6ce9e87725e5d1beb0ab135e9c55d453b06ce21b:Main:Asset"], "query": {"amount": "300000.0"} }