Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreign key mismatch issue in createAgent #386

Closed
rkreutzer opened this issue Feb 16, 2021 · 6 comments
Closed

Foreign key mismatch issue in createAgent #386

rkreutzer opened this issue Feb 16, 2021 · 6 comments
Labels
bug Something isn't working triage

Comments

@rkreutzer
Copy link
Contributor

Bug severity
4

Describe the bug
After performing a production build on an Ionic/Agular app, and then executing createAgent in the app, I receive the following:

query failed: INSERT INTO "temporary_l_verifier_d"("lHash", "dDid") SELECT "lHash", "dDid" FROM "l_verifier_d"
sqlite3_prepare_v2 failure: foreign key mismatch - "temporary_l_verifier_d" referencing "l""

To Reproduce
Steps to reproduce the behaviour:

  1. Create an Ionic/Angular app with agent methods
  2. Run "ionic capacitor copy android" -- the agent is created successfully
  3. Run "ionic capacitor copy android --prod" -- error received when trying to createAgent

Observed behaviour
The error is logged to the console, then the database is automatically closed

Expected behaviour
Production build should behave the same as a debug/development build

Versions (please complete the following information):

  • Veramo: 1.0.1
  • Browser Brave
  • Node Version 12.18.0
@rkreutzer rkreutzer added the bug Something isn't working label Feb 16, 2021
@jasheal
Copy link

jasheal commented Feb 17, 2021

We haven't done any testing specifically on Ionic/Cordova. However, there does appear to be some older issues relating to TypeOrm + Ionic. Keep us posted if you find anything relevant.

https://stackoverflow.com/questions/46708441/how-do-i-use-typeorm-with-ionic

@rkreutzer
Copy link
Contributor Author

The production build process does extra optimizations and code checking, so something is tripping it up. The debug and release builds work, so I'm still able to test. I looked at the link, but all the compiler options were set correctly.

Based on the insert statement that typeorm was executing, it appears to be associated with the presentation_verifier_identifier table, maybe how the foreign keys were defined. If someone that knows more about that section could take a look, that would be great.

@simonas-notcat simonas-notcat removed their assignment Feb 18, 2021
@trentlarson
Copy link
Contributor

trentlarson commented Mar 29, 2021

I hit this as well (when running with react-native on Android via the APK, even though running on the device with yarn run android works just fine). Here's my error, somewhat different: QueryFailedError: foreign key mismatch - "temporary_h_verifier_m" referencing "h" (code 1 SQLITE_ERROR): , while compiling: INSERT INTO "temporary_h_verifier_m"("hHash", "mDid") SELECT "hHash", "mDid" FROM "h_verifier_m"

I may have found a solution. (I say "may" because my fix may not be complete because there are other problems that I'm investigating.) I intend to submit some PRs because at least this needs to change:

  • Each entity in the @veramo/data-store has an @Entity() decoration. I found that my Android build changes the names of the classes, so any code that depends on the class name (eg. Key) will get the wrong name, usually something shorter like s or l. This causes things like QueryFailedError: no such table: s (code 1 SQLITE_ERROR): , while compiling: SELECT "s"."kid" AS "s_kid", "s"."kms" AS "s_kms", "s"."type" AS "s_type", "s"."publicKeyHex" AS "s_publicKeyHex", "s"."privateKeyHex" AS "s_privateKeyHex", "s"."meta" AS "s_meta", "s"."identifierDid" AS "s_identifierDid" FROM "s" "s" WHERE "s"."kid" IN (?). For the short-term, I've fixed every Entity() call in that library (both under src and build) to explicitly include the name of the class, in lowercase, and that fixed it.

Random note in my related debugging: the documentation has the connection config with synchronize: true. This doesn't cause this particular problem but it does use Entity calls under the covers and ends up crashing, and anyway that's not a setting that should be used on any production system so I'm writing the initial setup in SQL and doing migrations properly. Just had to mention it because the original problem manifests in many ways.

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jun 2, 2021
@trentlarson
Copy link
Contributor

I believe this is handled with this PR: #480
... so this can be closed now that it's merged.

@stale stale bot removed the wontfix This will not be worked on label Jun 4, 2021
@mirceanis
Copy link
Member

Closed by #480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

5 participants