Skip to content

Commit eea4cd5

Browse files
authored
Merge pull request #998 from airweave-ai/fix/cannot-use-direct
fix: cannot use direct crud user update method
2 parents 8af3140 + 405efba commit eea4cd5

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

backend/airweave/api/deps.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,9 @@ async def _authenticate_auth0_user(
5050
logger.error(f"User {auth0_user.email} not found in database")
5151
return None, AuthMethod.AUTH0, {}
5252

53-
# Update last active timestamp using CRUD module
54-
user = await crud.user.update(
55-
db=db,
56-
db_obj=user,
57-
obj_in={"last_active_at": datetime.utcnow()},
58-
current_user=user, # User updating their own record
59-
)
53+
# Update last active timestamp directly (can't use CRUD during auth flow)
54+
user.last_active_at = datetime.utcnow()
55+
user = await crud.user.update_user_no_auth(db, id=user.id, obj_in=user)
6056

6157
user_context = schemas.User.model_validate(user)
6258
return user_context, AuthMethod.AUTH0, {"auth0_id": auth0_user.id}

backend/airweave/crud/crud_user.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ async def get_by_email(self, db: AsyncSession, *, email: str) -> Optional[User]:
5151
raise NotFoundException(f"User with email {email} not found")
5252
return db_obj
5353

54+
async def update_user_no_auth(self, db: AsyncSession, *, id: UUID, obj_in: UserUpdate) -> User:
55+
"""Update a user without authentication.
56+
57+
Important: this method is not part of the regular CRUD operations.
58+
This is a custom method for updating a user, that does not
59+
require a current user. Use responsibly.
60+
61+
Args:
62+
db (AsyncSession): The database session.
63+
id (UUID): The UUID of the user to update.
64+
obj_in (UserUpdate): The updated user object.
65+
"""
66+
user = await self.get(db, id=id)
67+
if not user:
68+
raise NotFoundException(f"User with ID {id} not found")
69+
70+
for field, value in obj_in.model_dump(exclude_unset=True).items():
71+
setattr(user, field, value)
72+
73+
await db.commit()
74+
await db.refresh(user)
75+
return user
76+
5477
async def get(self, db: AsyncSession, id: UUID, current_user: User) -> Optional[User]:
5578
"""Get a single object by ID.
5679

0 commit comments

Comments
 (0)