Closed woylie closed 1 year ago
Thank you for the report! It seems that this is affecting a couple of environments. Is there an easy way to reproduce the problem?
Another question is whether you could identify the row with the FK that is missing.
I would also like to be interested if you ran the hydra janitor or any other clean up routine.
Thank you!
I did not run hydra janitor or other clean up routines. This occurs in my local dev environment without any sensitive data. The Hydra database dump only has 852 KB. I could send it to you on a private channel including the relevant parts of the docker compose config and hydra config. Just let me know where to send it.
Well, I think I didn't run any clean up routines. I might have manually deleted consent requests from the DB during development at some point.
Well, I think I didn't run any clean up routines. I might have manually deleted consent requests from the DB during development at some point.
That could be the problem!
Alright, I'll finish up updating our application first and try to run the migration on actual data I didn't tamper with then. I'll let you know whether I'll run into trouble.
@aeneasr We upgraded our staging environment to Hydra 2.0, ran the migrations, and we're seeing the same error. The data in the staging database has not been tampered with.
Thank you for the update! Do you have the rows affected by this available? It would be helpful to understand why they are pointing to something that does not exist!
Thank you for the update! Do you have the rows affected by this available? It would be helpful to understand why they are pointing to something that does not exist!
Is there an easy way to figure that out?
You will need to find all rows of hydra_oauth2_access
that have a field of consent_challenge_id
for which there is no row in hydra_oauth2_flow
(key consent_challenge_id
)
I sent you the query result via Slack.
I've tried to reproduce this doing the following:
For me this passed without problems. So the question is, why is the oauth2_flow
missing in your database and how can we reproduce that failure. You said you had this problem on docker-compose as well, if you have a clear reproducible path that would be tremendously helpful to fix the issue. Thanks!
I was able to run the migrations after running these queries.
update hydra_oauth2_access as t1 set challenge_id = null where challenge_id is not null and not exists (select null from hydra_oauth2_flow t2 where t1.challenge_id = t2.consent_challenge_id);
update hydra_oauth2_code as t1 set challenge_id = null where challenge_id is not null and not exists (select null from hydra_oauth2_flow t2 where t1.challenge_id = t2.consent_challenge_id);
update hydra_oauth2_oidc as t1 set challenge_id = null where challenge_id is not null and not exists (select null from hydra_oauth2_flow t2 where t1.challenge_id = t2.consent_challenge_id);
Unfortunately, I wouldn't know how to reproduce the issue either. I can only provide you with my local dev DB dump, which as I said I may have tampered with.
I think this can happen when a login session was deleted, which in turn deletes the login request/challenge. Then, in the migration, we merge login and consent tables, and potentially rows without a login reference are ignored, causing this problem.
Thank you for the query fix, we will retrospectively add this to the migrations. I'm wondering though if this has an effect on related access / refresh tokens and flows.
I checked the code, it does not seem that fosite requires the challenge_id
to function. So it should not have a major impact.
We got the same issue in local dev environment when upgrading from 1.11.5 to 2.0.2 No janitor or any other custom cleanup has been done.
And the following update was needed in addition to the 3 mentioned above:
update hydra_oauth2_refresh as t1 set challenge_id = null where challenge_id is not null and not exists(select null from hydra_oauth2_flow t2 where t1.challenge_id = t2.consent_challenge_id);
Preflight checklist
Describe the bug
I just tried to upgrade Hydra from 1.11.10 to 2.0.1 (tried upgrading to 2.0.0 first as well). However, I'm getting a FK constraint error when running the migrations.
How should I proceed?
Reproducing the bug
hydra migrate sql -e --yes --config /etc/config/hydra/hydra.yml
Relevant log output
Relevant configuration
No response
Version
2.0.1
On which operating system are you observing this issue?
macOS
In which environment are you deploying?
Docker Compose
Additional Context
No response