didx-xyz / aries-cloudapi-python

Apache License 2.0
12 stars 8 forks source link

TypeError: 'NoneType' object is not subscriptable #811

Closed wdbasson closed 5 months ago

wdbasson commented 5 months ago
"POST /tenant/v1/verifier/accept-request HTTP/1.1" 500 Internal Server Error

Occurs in regression tests

ACA-Py logs:

TypeError: 'NoneType' object is not subscriptable
    "accum": response_value["accum_to"]["value"]["accum"],
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/ledger/indy_vdr.py", line 1056, in get_revoc_reg_delta
    (delta, delta_timestamp) = await ledger.get_revoc_reg_delta(
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/protocols/present_proof/indy/pres_exch_handler.py", line 155, in return_presentation
    indy_proof = await indy_handler.return_presentation(
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/protocols/present_proof/v1_0/manager.py", line 274, in create_presentation
    ) = await presentation_manager.create_presentation(
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/protocols/present_proof/v1_0/routes.py", line 854, in presentation_exchange_send_presentation
    result = coro.send(None)
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 256, in __step
    raise self._exception
File "/usr/local/lib/python3.9/asyncio/futures.py", line 201, in result
    future.result()
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 328, in __wakeup
    yield self # This tells Task to wait for completion.
File "/usr/local/lib/python3.9/asyncio/futures.py", line 284, in __await__
    return await task
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/admin/server.py", line 449, in setup_context
    return await handler(request)
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/admin/server.py", line 384, in check_multitenant_authorization
    return await handler(request)
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/admin/server.py", line 335, in check_token
    return await handler(request)
File "/home/aries/.local/lib/python3.9/site-packages/aiohttp_apispec/middlewares.py", line 45, in validation_middleware
    return await handler(request)
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/admin/server.py", line 216, in debug_middleware
    return await handler(request)
File "/home/aries/.local/lib/python3.9/site-packages/aries_cloudagent/admin/server.py", line 179, in ready_middleware
    Traceback (most recent call last):
=================
Handler error with exception: 'NoneType' object is not subscriptable
Handler error: presentation_exchange_send_presentation
ff137 commented 5 months ago

I think I figured it out.

Our original test framework would create new tenants for each individual test. This made things easy, because "Alice" would always only have 1 credential. Now, in the regression test framework, "Alice" can now have potentially dozens of credentials.

With our verifier tests, we fetch relevant credentials for a proof, which can now match more than one credential. We always just take the first one in the list, because previously we assumed there is only one for Alice. This means it can (non-deterministically) provide a revocable credential for a proof, instead of the intended non-revocable credential.

Since our tests include in the proof request that it must be non-revoked between some arbitrary timeframe, ACA-Py sees this request, and that a revocable credential is provided, and tries to look up the "delta of the accumulated state" for the revocation registry associated with the credential.

For some reason, the ledger provides ACA-Py with an unusable response, because the response is missing some expected fields. Here's a sample of a problematic response that ACA-Py gets from indy_vdr.get_revoc_reg_delta:

{
  "from": 0,
  "revocRegDefId": "HBv6i91c7E3LKPXwp4jzoo:4:HBv6i91c7E3LKPXwp4jzoo:3:CL:14:RegressionTestTag:CL_ACCUM:f55a32e5-aece-4cb5-889f-da8e02b01b23",
  "to": 20,
  "type": "117",
  "data": {
    "stateProofFrom": null,
    "value": {
      "accum_to": null,
      "accum_from": null
    }
  },
  "identifier": "LibindyDid111111111111",
  "reqId": 1716277988080577000,
  "seqNo": null,
  "txnTime": null
}

ACA-Py expects data.value.accum_to to exist, but instead, for whatever reason, we get None. I have no clue why it returns None, but that is the source of the issue.

So, a fix for our tests would be to ensure we always only provide the non-revocable credentials. i.e. in the proof requests, add a restriction by credential definition id. That's easy. But more important would be to understand why the ledger response is missing expected values to begin with, and also to contribute some improved error handling to ACA-Py, so we get more meaningful response than the TypeError.

ff137 commented 5 months ago

Fixed with the following: https://github.com/didx-xyz/aries-cloudapi-python/pull/806/commits/217b647c2a29ea67a68e3c1753054bf7ac888748 adds restrictions to which credentials match the proof