Skip to content

chore(api): migrate mail task and OAuth data source to use Session(db…#35235

Open
jerryzai wants to merge 3 commits intolanggenius:mainfrom
jerryzai:chore/sqlalchemy-session-mail-oauth
Open

chore(api): migrate mail task and OAuth data source to use Session(db…#35235
jerryzai wants to merge 3 commits intolanggenius:mainfrom
jerryzai:chore/sqlalchemy-session-mail-oauth

Conversation

@jerryzai
Copy link
Copy Markdown

Summary

  • mail_clean_document_notify_task.py: wrap all DB operations in a single with Session(db.engine) as session: block so that ORM objects fetched early in the task (logs, tenants, accounts) remain live when their attributes are accessed later in the loop
  • oauth_data_source.py: migrate each method (get_access_token, save_internal_access_token, sync_data_source) to use an explicit session; the DataSourceOauthBinding record is read, mutated, and committed within the same session block

Files changed

  • api/schedule/mail_clean_document_notify_task.py
  • api/libs/oauth_data_source.py

Motivation

Part of #24138. Both files perform multi-step read-then-write patterns that are a natural fit for pure SQLAlchemy unit-of-work sessions.

Test plan

  • Unit tests pass
  • Document-clean notification emails are sent correctly in a sandboxed environment
  • Notion OAuth token exchange and sync flows work correctly

@jerryzai jerryzai requested a review from QuantumGhost as a code owner April 15, 2026 02:22
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

No changes detected.

@jerryzai jerryzai force-pushed the chore/sqlalchemy-session-mail-oauth branch from dd1ce03 to a438b27 Compare April 15, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant