Repository navigation
Fix OAuth PKCE session update: add missing updated_at column - #7
Merged
Merged
Conversation
Root cause: The auth_session table had a BEFORE UPDATE trigger calling updated_at_column() which sets NEW.updated_at, but the table schema never included an updated_at column, causing SQLSTATE 42703 error. This broke CreatePKCERequestSession UPDATE path when called after login in production OAuth flow (Affyard MCP → /oauth/authorize → login → authorize → CreateAuthorizeCodeSession → CreatePKCERequestSession UPDATE). Changes: - Add updated_at column to auth_session table (migration 011) - Add UpdatedAt field to AuthSession model to align with schema - Update tests to account for GORM auto-updating updated_at - Preserve UNIQUE(access_token) + UPDATE-by-access_token behavior The trigger existed since initial migration (003_auth.up.sql line 102-103) and matches the pattern used on auth_client which does have updated_at. This fix aligns auth_session with that pattern. Test coverage: TestCreatePKCERequestSessionUpdatesExistingSession now exercises the full UPDATE path with proper updated_at handling. Co-authored-by: Dmitry <demdxx@gmail.com>
The go.mod file requires Go 1.26.0, but the CI workflow was still using Go 1.25.x, causing compilation errors in tests. Co-authored-by: Dmitry <demdxx@gmail.com>
Coverage Report for CI Build 35356819848Warning No base build found for commit Coverage: 3.918%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Production OAuth authorize fails after login when creating the authorize response / PKCE session update.
Error (2026-09-18 ~14:20 UTC):
Flow: Cursor MCP OAuth →
/oauth/authorize→ user logs in → authorize again → CreateAuthorizeCodeSession → CreatePKCERequestSession UPDATE failsRoot Cause
The
auth_sessiontable has aBEFORE UPDATEtrigger (since initial migration003_auth.up.sqlline 102-103):This trigger calls
updated_at_column()which setsNEW.updated_at = now(), but theauth_sessiontable schema never included anupdated_atcolumn, causing the PostgreSQL error.The trigger was copied from
auth_client(which hasupdated_at), but the column was never added toauth_session.Solution
Added
updated_atcolumn to align schema ↔ model ↔ trigger:updated_at TIMESTAMP NOT NULL DEFAULT NOW()toauth_sessiontableUpdatedAt time.Timefield toAuthSessionstructupdated_atin UPDATE statementsThis aligns
auth_sessionwith the pattern used onauth_clientand makes the existing trigger work correctly.Changes
deploy/migrations/initial/011_auth_session_updated_at.up.sql- Add updated_at columndeploy/migrations/initial/011_auth_session_updated_at.down.sql- Rollback migrationrepository/authclient/models/auth_session.go- Add UpdatedAt fieldpkg/auth/oauth2/serverprovider/storage_test.go- Update tests for new fieldPreserved behavior:
Testing
TestCreatePKCERequestSessionUpdatesExistingSession- exercises full UPDATE pathTestCreateRefreshTokenSessionUpdatesByPrimaryKey- verifies updated_at in other UPDATENext Steps
After merge:
Notes