fix: SQLAlchemy async lazy loading for new users
Initialize user.roles=[] and user.preferences on new user creation to avoid MissingGreenlet error in async context. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
7ab9f73a1d
commit
e3a49c800a
@@ -130,11 +130,14 @@ class AuthService:
|
||||
avatar_url=token_info.picture,
|
||||
last_login=datetime.now(timezone.utc),
|
||||
)
|
||||
# Initialize relationships to avoid lazy loading issues in async
|
||||
user.roles = []
|
||||
self.session.add(user)
|
||||
await self.session.flush() # Get the user ID
|
||||
|
||||
# Create default preferences
|
||||
# Create default preferences and attach to user
|
||||
preferences = UserPreferences(user_id=user.id)
|
||||
user.preferences = preferences
|
||||
self.session.add(preferences)
|
||||
|
||||
logger.info(f"Created new user: {token_info.email}")
|
||||
|
||||
Reference in New Issue
Block a user