Skip to content

Conversation

@dominic-r
Copy link
Member

@dominic-r dominic-r commented Dec 29, 2025

FailoverRouter was routing reads to replicas even inside active transactions. This caused the application wizard to fail with "Invalid pk - object does not exist" when using read replicas (mabye other things too, have not checked), as FK validation queries couldn't see uncommitted rows on the primary

When authentik is configured with pg read replicas, the application wizard fails with "Invalid pk - object does not exist" for the provider field.

The issue occurs in the blueprint validation flow:
1.  Provider is created on the primary database (e.g PK 159)
2. KeyOf.resolve() returns this PK for the application's provider field
3. ApplicationSerializer.is_valid() validates the provider FK
4. DRF's PrimaryKeyRelatedField queries to verify the PK exists
5. FailoverRouter routes this read to a replica
6. Replica hasn't replicated the new provider yet --> validation fails

Number 6 happens because the transaction has not been commited yet cause blueprint validation runs in transaction_rollback()

The fix introduces TransactionApplicationRequestSerializer which excludes provider-related fields (provider, provider_obj, backchannel_providers, backchannel_providers_obj) from validation.

This is safe because:
- The provider is created in the same blueprint transaction
- The KeyOf reference correctly links them during blueprint apply()
- The blueprint importer handles the actual FK assignment
@dominic-r dominic-r added this to the Release 2025.12 milestone Dec 29, 2025
@dominic-r dominic-r requested a review from BeryJu December 29, 2025 03:20
@dominic-r dominic-r self-assigned this Dec 29, 2025
@dominic-r dominic-r requested a review from a team as a code owner December 29, 2025 03:20
@netlify
Copy link

netlify bot commented Dec 29, 2025

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit b275657
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/695ee38fad5b8f000884dee7
😎 Deploy Preview https://deploy-preview-19086--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dominic-r dominic-r added the backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12 label Dec 29, 2025
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.34%. Comparing base (660a587) to head (afe1deb).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
authentik/tenants/db.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19086      +/-   ##
==========================================
+ Coverage   93.15%   93.34%   +0.19%     
==========================================
  Files         949      949              
  Lines       52384    52388       +4     
==========================================
+ Hits        48797    48904     +107     
+ Misses       3587     3484     -103     
Flag Coverage Δ
conformance 38.75% <66.66%> (+<0.01%) ⬆️
e2e 44.64% <66.66%> (+1.01%) ⬆️
integration 23.43% <66.66%> (+<0.01%) ⬆️
unit 91.57% <66.66%> (-0.02%) ⬇️
unit-migrate 91.61% <66.66%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 29, 2025

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-afe1debcc490ff614d3bb9d08d6e4ba49d6b6021
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
    image:
        repository: ghcr.io/goauthentik/dev-server
        tag: gh-afe1debcc490ff614d3bb9d08d6e4ba49d6b6021

Afterwards, run the upgrade commands from the latest release notes.

@dominic-r dominic-r added the backport/version-2025.10 Add this label to PRs to backport changes to version-2025.10 label Dec 29, 2025
@dominic-r dominic-r changed the title core: fix transactional app creation failing with read replicas core: fix read replica routing during transactions Jan 7, 2026
@netlify
Copy link

netlify bot commented Jan 7, 2026

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit b275657
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/695ee38f98a67a00083288ce
😎 Deploy Preview https://deploy-preview-19086--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dominic-r dominic-r requested review from gergosimonyi and removed request for BeryJu January 7, 2026 23:10
Copy link
Collaborator

@gergosimonyi gergosimonyi left a comment

Choose a reason for hiding this comment

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

@BeryJu I think this is the correct approach, but I'll leave the checkmark up to you.

@gergosimonyi gergosimonyi requested a review from BeryJu January 7, 2026 23:22
Copy link
Member

@BeryJu BeryJu left a comment

Choose a reason for hiding this comment

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

LGTM, cc @rissson

@github-project-automation github-project-automation bot moved this from Todo to In Progress in authentik Core Jan 8, 2026
@dominic-r dominic-r enabled auto-merge (squash) January 8, 2026 00:24
@dominic-r dominic-r merged commit d7f9172 into main Jan 8, 2026
181 of 186 checks passed
@dominic-r dominic-r deleted the sdko/fix-wizard-on-read-replicas branch January 8, 2026 01:41
@github-project-automation github-project-automation bot moved this from In Progress to Done in authentik Core Jan 8, 2026
authentik-automation bot pushed a commit that referenced this pull request Jan 8, 2026
* core: fix transactional app creation failing with read replicas

When authentik is configured with pg read replicas, the application wizard fails with "Invalid pk - object does not exist" for the provider field.

The issue occurs in the blueprint validation flow:
1.  Provider is created on the primary database (e.g PK 159)
2. KeyOf.resolve() returns this PK for the application's provider field
3. ApplicationSerializer.is_valid() validates the provider FK
4. DRF's PrimaryKeyRelatedField queries to verify the PK exists
5. FailoverRouter routes this read to a replica
6. Replica hasn't replicated the new provider yet --> validation fails

Number 6 happens because the transaction has not been commited yet cause blueprint validation runs in transaction_rollback()

The fix introduces TransactionApplicationRequestSerializer which excludes provider-related fields (provider, provider_obj, backchannel_providers, backchannel_providers_obj) from validation.

This is safe because:
- The provider is created in the same blueprint transaction
- The KeyOf reference correctly links them during blueprint apply()
- The blueprint importer handles the actual FK assignment

* wip

* wip

* wip

* wip

* wip

* wip
@authentik-automation
Copy link
Contributor

🍒 Cherry-pick to version-2025.10 created: #19240

authentik-automation bot pushed a commit that referenced this pull request Jan 8, 2026
* core: fix transactional app creation failing with read replicas

When authentik is configured with pg read replicas, the application wizard fails with "Invalid pk - object does not exist" for the provider field.

The issue occurs in the blueprint validation flow:
1.  Provider is created on the primary database (e.g PK 159)
2. KeyOf.resolve() returns this PK for the application's provider field
3. ApplicationSerializer.is_valid() validates the provider FK
4. DRF's PrimaryKeyRelatedField queries to verify the PK exists
5. FailoverRouter routes this read to a replica
6. Replica hasn't replicated the new provider yet --> validation fails

Number 6 happens because the transaction has not been commited yet cause blueprint validation runs in transaction_rollback()

The fix introduces TransactionApplicationRequestSerializer which excludes provider-related fields (provider, provider_obj, backchannel_providers, backchannel_providers_obj) from validation.

This is safe because:
- The provider is created in the same blueprint transaction
- The KeyOf reference correctly links them during blueprint apply()
- The blueprint importer handles the actual FK assignment

* wip

* wip

* wip

* wip

* wip

* wip
@authentik-automation
Copy link
Contributor

🍒 Cherry-pick to version-2025.12 created: #19241

rissson pushed a commit that referenced this pull request Jan 8, 2026
…to version-2025.12) (#19241)

Co-authored-by: Dominic R <[email protected]>
fix read replica routing during transactions (#19086)
rissson pushed a commit that referenced this pull request Jan 8, 2026
…to version-2025.10) (#19240)

Co-authored-by: Dominic R <[email protected]>
fix read replica routing during transactions (#19086)
kensternberg-authentik added a commit that referenced this pull request Jan 8, 2026
* main:
  stages/prompt: optimize API endpoints (#19251)
  web: bump the rollup group across 1 directory with 4 updates (#19206)
  web: bump vite from 7.3.0 to 7.3.1 in /web (#19245)
  website/docs: update github social login script example (#19246)
  website/integrations: update AWS (#17861)
  core: bump goauthentik.io/api/v3 from 3.2026020.8 to 3.2026020.10 (#19242)
  website: Fix typos. (#19243)
  core: fix read replica routing during transactions (#19086)
  website/glossary: improve (#18969)
  stages/authenticator_static: set max token length to 100 chars (#19162)
kensternberg-authentik added a commit that referenced this pull request Jan 12, 2026
* main: (44 commits)
  web: Fix flow inspector advancement event. (#19309)
  web: bump knip from 5.80.0 to 5.80.1 in /web (#19301)
  core: bump urllib3 from 2.5.0 to v2.6.3 (#19287)
  endpoints: show agent version (#19239)
  core: bump django from v5.2.9 to 5.2.10 (#19290)
  web/admin: add banner to flow import form (#19288)
  web: bump chromedriver from 143.0.3 to 143.0.4 in /web (#19244)
  stages/password: replace session-based retries with reputation (#18643)
  website/integations: fix aws spelling (#19253)
  website/docs: update entra id provider docs (#18366)
  stages/prompt: optimize API endpoints (#19251)
  web: bump the rollup group across 1 directory with 4 updates (#19206)
  web: bump vite from 7.3.0 to 7.3.1 in /web (#19245)
  website/docs: update github social login script example (#19246)
  website/integrations: update AWS (#17861)
  core: bump goauthentik.io/api/v3 from 3.2026020.8 to 3.2026020.10 (#19242)
  website: Fix typos. (#19243)
  core: fix read replica routing during transactions (#19086)
  website/glossary: improve (#18969)
  stages/authenticator_static: set max token length to 100 chars (#19162)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend backport/version-2025.10 Add this label to PRs to backport changes to version-2025.10 backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants