refactor: select in console auth, setup and apikey#33790
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request modernizes the database interaction layer in key console controllers by adopting SQLAlchemy 2.0's declarative Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-20 02:36:33.939152609 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-20 02:36:24.756088533 +0000
@@ -1,3 +1,5 @@
+ERROR `>=` is not supported between `None` and `int` [unsupported-operation]
+ --> controllers/console/apikey.py:89:12
ERROR `result` may be uninitialized [unbound-name]
--> controllers/console/app/annotation.py:126:16
ERROR Object of class `App` has no attribute `access_mode` [missing-attribute]
@@ -27,9 +29,9 @@
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/ping.py:10:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
- --> controllers/console/setup.py:39:2
+ --> controllers/console/setup.py:40:2
ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
- --> controllers/console/setup.py:64:2
+ --> controllers/console/setup.py:65:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/version.py:30:2
ERROR `result` may be uninitialized [unbound-name]
|
There was a problem hiding this comment.
Code Review
This pull request correctly refactors legacy SQLAlchemy db.session.query() calls to the modern SQLAlchemy 2.0 select() style in several console-related files. The changes are consistent with the goal of modernizing the data access layer, and the corresponding unit tests have been updated appropriately. I have one suggestion for improvement in api/controllers/console/wraps.py to simplify the logic and avoid a redundant database query, which will enhance both readability and performance.
6a95171 to
e641df2
Compare
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-20 03:03:42.470605344 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-20 03:03:33.862607448 +0000
@@ -27,9 +27,9 @@
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/ping.py:10:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
- --> controllers/console/setup.py:39:2
+ --> controllers/console/setup.py:40:2
ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
- --> controllers/console/setup.py:64:2
+ --> controllers/console/setup.py:65:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/version.py:30:2
ERROR `result` may be uninitialized [unbound-name]
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-20 13:26:44.686302655 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-20 13:26:35.420251095 +0000
@@ -27,9 +27,9 @@
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/ping.py:10:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
- --> controllers/console/setup.py:39:2
+ --> controllers/console/setup.py:40:2
ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
- --> controllers/console/setup.py:64:2
+ --> controllers/console/setup.py:65:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/version.py:30:2
ERROR `result` may be uninitialized [unbound-name]
|
0483ec8 to
31730f1
Compare
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-20 14:00:40.483284421 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-20 14:00:30.177286477 +0000
@@ -27,9 +27,9 @@
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/ping.py:10:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
- --> controllers/console/setup.py:39:2
+ --> controllers/console/setup.py:40:2
ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
- --> controllers/console/setup.py:64:2
+ --> controllers/console/setup.py:65:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/version.py:30:2
ERROR `result` may be uninitialized [unbound-name]
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-20 16:11:31.559959845 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-20 16:11:21.306013847 +0000
@@ -27,9 +27,9 @@
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/ping.py:10:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
- --> controllers/console/setup.py:39:2
+ --> controllers/console/setup.py:40:2
ERROR Object of class `MissingRouter` has no attribute `post` [missing-attribute]
- --> controllers/console/setup.py:64:2
+ --> controllers/console/setup.py:65:2
ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]
--> controllers/console/version.py:30:2
ERROR `result` may be uninitialized [unbound-name]
|
|
@asukaminato0721 Can you review my PR please? I think current test failures are not in my changes. |
|
Thanks. |
Summary
db.session.query()calls to SQLAlchemy 2.0select()style incontrollers/console/auth, setup, and API key filesChanges
controllers/console/wraps.py.query(DifySetup).first()→scalar(select(DifySetup).limit(1))controllers/console/setup.py.query(DifySetup).first()→scalar(select(DifySetup).limit(1))controllers/console/apikey.py.query().count()→scalar(select(func.count(...))),.query().first()→scalar(select(...).limit(1)),.query().delete()→execute(delete(...))tests/.../test_wraps.py.query.return_value.firstto.scalartests/.../test_apikey.py.query.return_value.where.return_value.firstto.scalarTest plan
ruff checkandruff formatpass