Skip to content

fix(anoncreds-upgrade): tag cred defs with their own schema and fix Schema.create argument order - #4301

Merged
jamshale merged 4 commits into
openwallet-foundation:mainfrom
kutluhaneth46:fix/anoncreds-cred-def-schema
Dec 4, 2026
Merged

jamshale merged 4 commits into
openwallet-foundation:mainfrom
kutluhaneth46:fix/anoncreds-cred-def-schema

Conversation

@kutluhaneth46

Copy link
Copy Markdown
Contributor

Part of #4175

Summary

While reproducing #4175 against the public BCovrin test ledger (askar to askar-anoncreds issuer upgrade), I found two bugs in acapy_agent/wallet/anoncreds_upgrade.py that corrupt the migrated schema and credential definition records. Both are fixed here.

  1. upgrade_all_records_with_transaction: every credential definition was tagged with the schema of the last loop iteration, because the loop reused schema_upgrade_obj.schema instead of looking up the schema by the cred def's schema_id. Schemas are now indexed by id and each cred def gets its own schema.
  2. get_schema_upgrade_object: Schema.create received (schema_id, schema_name, ...) while its signature is (name, version, issuer_id, attr_names), so the schema id ended up in name and the schema name in version. The arguments are now passed in the correct order.

Testing

  • Issuer upgrade repro on the BCovrin test ledger: before the fix, the migrated tags were wrong; after the fix they match a fresh askar-anoncreds wallet.
  • Added test_upgrade_cred_defs_use_their_own_schema and test_schema_upgrade_object_keeps_schema_name_and_version.
  • acapy_agent/wallet/tests/test_anoncreds_upgrade.py: all tests pass.
  • Full pytest acapy_agent run: passes.
  • ruff check and ruff format --check pass on both changed files.

Notes

This PR does not claim to fix the credential-loss part of #4175. In my holder-side repro (issuer and holder on askar, upgrade to askar-anoncreds), the credential stayed visible on /credentials after the restart, with both sqlite and postgres storage. The kanon-anoncreds holder path showed an empty /credentials result, but in this codebase there is no base kanon wallet type, and the restart opens a separate store (dbstore/sqlite_dbstore.db) that the upgrade does not populate. I have not changed that path here.

@kutluhaneth46
kutluhaneth46 force-pushed the fix/anoncreds-cred-def-schema branch from 1a97d5e to 717d33f Compare December 3, 2026 22:32
upgrade_all_records_with_transaction passed the schema from the last
loop iteration to every cred def upgrade, so cred defs issued under an
earlier schema were rewritten with the wrong schema name, version and
issuer. Look up the schema by the cred def's schema_id instead, and fail
the upgrade explicitly if the schema record is missing.

Signed-off-by: KutluhanETH <kutluhaneth46@users.noreply.github.com>
get_schema_upgrade_object called Schema.create(issuer_id-less positional
args) as (schema_id, name, issuer_did, attrs), but the signature is
(name, version, issuer_id, attr_names). Upgraded schemas therefore had the
schema id as their name and the schema name as their version, and the
cred defs built from them carried the same swapped schema_name and
schema_version tags, so filtering by schema_name returned nothing. Pass the
stored schema_name and schema_version instead.

Signed-off-by: KutluhanETH <kutluhaneth46@users.noreply.github.com>
Signed-off-by: KutluhanETH <kutluhaneth46@users.noreply.github.com>
@kutluhaneth46
kutluhaneth46 force-pushed the fix/anoncreds-cred-def-schema branch from 717d33f to 7ea781e Compare December 3, 2026 22:33
Signed-off-by: KutluhanETH <kutluhaneth46@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@kutluhaneth46

Copy link
Copy Markdown
Contributor Author

Hi, I pushed an empty commit (c009e4d) to re-trigger the BDD Integration Tests after the earlier run failed on a ledger upload timeout in 0586-sign-transaction @3.1.

The re-run did not come back green. It now fails in two revocation scenarios from the same feature (@1.1 and @3.1) with an assertion failure during the revocation registry entry step. Both scenarios exercise the endorsement and revocation registry path, not the Askar to AnonCreds upgrade path this PR changes, and the same workflow is green on main at the same base commit (f91dfe3). So this looks flaky to me, but I cannot fully rule out an interaction.

Everything else on the head is green (lint, unit tests, PostgreSQL integration, CodeQL, SonarCloud, DCO). Could a maintainer re-run the BDD job or check whether these scenarios are known flakes? I can also adjust the PR if something specific should change. Thank you!

@jamshale jamshale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hoping this isn't a huge issue because we've already upgraded wallets in production. I don't think this lookup should cause major issues. Thanks for finding and fixing it.

@jamshale
jamshale merged commit 23abd62 into openwallet-foundation:main Dec 4, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants