Fix user audit trail logging stale agency value for old and new
Expire the SQLAlchemy cached user object after flush() so the subsequent get_by_id() reloads the agency relationship with fresh data. Previously the identity map returned the same Python object with the old .agency, causing audit logs to record identical old and new values on agency changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
bcc20260de
commit
7f1df8c508
1 changed files with 1 additions and 1 deletions
|
|
@ -116,7 +116,7 @@ class UserRepository:
|
|||
if agency_id is not ...:
|
||||
user.agency_id = agency_id
|
||||
await self.session.flush()
|
||||
# Re-fetch to get agency relationship loaded
|
||||
self.session.expire(user) # Clear cached state so relationship reloads
|
||||
return await self.get_by_id(user_id)
|
||||
|
||||
async def list_agencies(self) -> list[Agency]:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue