refactor: replace db.session with sessionmaker in console controllers#35228
Open
wdeveloper16 wants to merge 10 commits intolanggenius:mainfrom
Open
refactor: replace db.session with sessionmaker in console controllers#35228wdeveloper16 wants to merge 10 commits intolanggenius:mainfrom
wdeveloper16 wants to merge 10 commits intolanggenius:mainfrom
Conversation
Contributor
Pyrefly DiffNo changes detected. |
1 similar comment
Contributor
Pyrefly DiffNo changes detected. |
0bffe5a to
e89300b
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 00:06:02.917223207 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 00:05:51.927117397 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:594:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:595:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:596:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:597:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 00:08:27.682055219 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 00:08:16.812126437 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:594:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:595:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:596:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:597:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
dca35a3 to
f2a5897
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 00:44:06.928821681 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 00:43:56.554764837 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:593:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:594:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:595:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:596:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 00:46:51.257040018 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 00:46:40.674055851 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:593:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:594:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:595:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:596:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
98f2879 to
709624c
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 01:12:37.621770243 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 01:12:27.142766532 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:600:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:601:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:602:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:603:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 01:14:43.784469638 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 01:14:33.537400323 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:600:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:601:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:602:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:603:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
4c66cff to
f59c9f9
Compare
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 02:01:40.166806888 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 02:01:29.952572477 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:600:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:601:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:602:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:603:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 02:03:51.639260068 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 02:03:40.785265046 +0000
@@ -2003,13 +2003,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:600:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:601:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:602:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:603:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors console controllers to stop using db.session directly and instead use explicit SQLAlchemy sessionmaker sessions, aligning with the ongoing move toward engine-based session management.
Changes:
- Migrate
api/controllers/console/admin.pyendpoints tosessionmaker(...).begin()sessions (including explore apps, banners, and chunked notification account lookups). - Migrate
api/controllers/console/explore/installed_app.pyto explicit sessions, keeping list construction inside the session and usingmerge()before mutation indelete/patch. - Update unit tests to patch
db.engineand mocksessionmaker(...).begin()flows.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| api/controllers/console/admin.py | Replaces mixed db.session/custom session usage with a consistent sessionmaker-based session scope. |
| api/controllers/console/explore/installed_app.py | Moves DB operations to explicit sessions; ensures relationships are accessed before detach; uses merge() for updates/deletes. |
| api/tests/unit_tests/controllers/console/test_admin.py | Updates admin controller tests to mock sessionmaker sessions and patch db.engine. |
| api/tests/unit_tests/controllers/console/explore/test_installed_app.py | Updates installed-app controller tests to mock sessionmaker sessions and patch db.engine. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…d_app.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 02:39:00.954848629 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 02:38:51.361744256 +0000
@@ -2001,13 +2001,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:601:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:602:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:603:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:604:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-15 02:39:07.365028984 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-15 02:38:56.843052103 +0000
@@ -2001,13 +2001,13 @@
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `NoneType` has no attribute `get`
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:657:29
+ --> tests/unit_tests/controllers/console/test_admin.py:601:29
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:658:34
+ --> tests/unit_tests/controllers/console/test_admin.py:602:34
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:659:39
+ --> tests/unit_tests/controllers/console/test_admin.py:603:39
ERROR Object of class `str` has no attribute `get` [missing-attribute]
- --> tests/unit_tests/controllers/console/test_admin.py:660:42
+ --> tests/unit_tests/controllers/console/test_admin.py:604:42
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
--> tests/unit_tests/controllers/console/test_extension.py:14:5
ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
|
Contributor
Author
|
Hi, @asukaminato0721 |
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.
Summary
controllers/console/admin.pyandcontrollers/console/explore/installed_app.pyto explicitsessionmakersessions.admin.py: consolidates the previously mixedsession_factory.create_session()+db.sessionpattern inInsertExploreAppListApi.postinto a singleexpire_on_commit=Falsesession so the lazy-loadedapp.siterelationship isaccessible;
InsertExploreAppApi.deletesimilarly consolidated from three separate sessions into one; banner insert/delete and the chunked email-lookup loop use targeted write sessions.installed_app.py: thegetlist-build is moved inside the session so the lazy-loadedinstalled_app.apprelationship is resolved before detach;postconsolidates all reads and the conditional insert into one session;deleteandpatchusesession.merge()to re-attach the passed-ininstalled_appobject before mutation.Test plan
can_trial=true; verifyTrialApprow is created.batch_add_notification_accountswith a CSV file and with a JSON body; verify matched account IDs are forwarded correctly.Part of #24138.