Skip to content

refactor: select in console auth, setup and apikey#33790

Merged
asukaminato0721 merged 3 commits intolanggenius:mainfrom
RenzoMXD:refactor/select-api-migration-console-auth-setup
Mar 21, 2026
Merged

refactor: select in console auth, setup and apikey#33790
asukaminato0721 merged 3 commits intolanggenius:mainfrom
RenzoMXD:refactor/select-api-migration-console-auth-setup

Conversation

@RenzoMXD
Copy link
Contributor

Summary

  • Migrate legacy db.session.query() calls to SQLAlchemy 2.0 select() style in controllers/console/ auth, setup, and API key files
  • Update corresponding unit test mocks to match new query patterns
  • Part of use select style api in orm #22668

Changes

File Occurrences Migration
controllers/console/wraps.py 2 .query(DifySetup).first()scalar(select(DifySetup).limit(1))
controllers/console/setup.py 1 .query(DifySetup).first()scalar(select(DifySetup).limit(1))
controllers/console/apikey.py 3 .query().count()scalar(select(func.count(...))), .query().first()scalar(select(...).limit(1)), .query().delete()execute(delete(...))
tests/.../test_wraps.py 2 Updated mocks from .query.return_value.first to .scalar
tests/.../test_apikey.py 2 Updated mocks from .query.return_value.where.return_value.first to .scalar

Test plan

  • ruff check and ruff format pass
  • All 26 related unit tests pass

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Mar 20, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 select() style. This refactoring improves code consistency, leverages newer SQLAlchemy features, and enhances maintainability by moving away from deprecated query patterns. The changes ensure that the application's data access logic is up-to-date with current best practices, and accompanying unit tests have been updated to reflect these changes.

Highlights

  • SQLAlchemy 2.0 Migration: Migrated legacy db.session.query() calls to the modern SQLAlchemy 2.0 select() style within console authentication, setup, and API key controllers.
  • Query Pattern Updates: Updated various query patterns including .count(), .first(), and .delete() to their SQLAlchemy 2.0 equivalents using scalar(select(func.count(...))), scalar(select(...).limit(1)), and execute(delete(...)) respectively.
  • Unit Test Adjustments: Modified corresponding unit test mocks to align with the new SQLAlchemy 2.0 query patterns, specifically updating mock return values from .query.return_value.first to .scalar.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

Pyrefly Diff

base → 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]

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RenzoMXD RenzoMXD force-pushed the refactor/select-api-migration-console-auth-setup branch from 6a95171 to e641df2 Compare March 20, 2026 03:02
@github-actions
Copy link
Contributor

Pyrefly Diff

base → 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]

@github-actions
Copy link
Contributor

Pyrefly Diff

base → 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]

@RenzoMXD RenzoMXD force-pushed the refactor/select-api-migration-console-auth-setup branch from 0483ec8 to 31730f1 Compare March 20, 2026 13:57
@github-actions
Copy link
Contributor

Pyrefly Diff

base → 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]

@github-actions
Copy link
Contributor

Pyrefly Diff

base → 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]

@RenzoMXD
Copy link
Contributor Author

@asukaminato0721 Can you review my PR please? I think current test failures are not in my changes.

@langgenius langgenius deleted a comment Mar 21, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 21, 2026
@asukaminato0721 asukaminato0721 merged commit 609258f into langgenius:main Mar 21, 2026
11 of 14 checks passed
@RenzoMXD RenzoMXD deleted the refactor/select-api-migration-console-auth-setup branch March 21, 2026 09:07
@RenzoMXD
Copy link
Contributor Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants