Repository navigation
Fix OAuth GetByToken panic with GORM many-to-many relation - #9
Merged
Merged
Conversation
The GetByToken method was scanning into a generic Member[TUser, TAccount] struct, causing GORM's reflect.StructOf to panic when processing the many-to-many Roles relation with invalid field names from generic types. Changed to scan into models.MemberBase directly, since the Account and User relations are fetched separately anyway. This avoids the GORM schema-building issue with generic types. Added test coverage for GetByToken to prevent regression. Co-authored-by: Dmitry <demdxx@gmail.com>
demdxx
marked this pull request as ready for review
September 18, 2026 16:06
Coverage Report for CI Build 35365839180Coverage increased (+0.1%) to 4.203%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. 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
Affyard MCP OAuth token exchange succeeded, but the first authenticated
POST /mcppanicked when resolving the access token to a user/account:Root Cause
The
GetByTokenmethod was scanning into a genericMember[TUser, TAccount]struct that embedsMemberBase(which has a many-to-manyRolesrelation). When GORM tried to dynamically build a struct viareflect.StructOfto process the many-to-many relation, it encountered the generic type parameters (TUser,TAccount) and panicked because these don't produce valid field names for reflection.Solution
Changed
GetByTokento scan intomodels.MemberBasedirectly instead of the full genericMember[TUser, TAccount]type. TheAccountandUserrelations on the generic Member type weren't being used anyway — they're fetched separately with explicitdb.First()calls immediately after.This avoids GORM's schema-building issue with generic types while maintaining identical behavior.
Testing
TestGetByTokencovering the full OAuth access token → user/account flowAffyard Impact
Affyard can bump the blaze-api submodule after this merge to resolve the MCP OAuth panic.