refactor: select in tag_service#34441
Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom Apr 2, 2026
Merged
Conversation
Contributor
Pyrefly DiffNo changes detected. |
Contributor
Pyrefly DiffNo changes detected. |
asukaminato0721
approved these changes
Apr 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors TagService’s ORM access to SQLAlchemy 2.x select()-style statements to improve typing and align with the project’s ongoing migration away from db.session.query() (per #22668).
Changes:
- Migrated legacy
db.session.query(...)usages inTagServicetoselect(...)statements. - Replaced
.first()/.count()patterns withdb.session.scalar(...)andselect(func.count(...)). - Updated join-based queries to use
db.session.scalars(...)/db.session.execute(...)in 2.x style.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| results: list = query.order_by(Tag.created_at.desc()).all() | ||
| stmt = stmt.where(sa.and_(Tag.name.ilike(f"%{escaped_keyword}%", escape="\\"))) | ||
| stmt = stmt.group_by(Tag.id, Tag.type, Tag.name, Tag.created_at) | ||
| results: list = list(db.session.execute(stmt.order_by(Tag.created_at.desc())).all()) |
There was a problem hiding this comment.
db.session.execute(...).all() already returns a list, so wrapping it in list(...) is redundant. Dropping the extra list() avoids an unnecessary copy and keeps the intent clearer.
Suggested change
| results: list = list(db.session.execute(stmt.order_by(Tag.created_at.desc())).all()) | |
| results: list = db.session.execute(stmt.order_by(Tag.created_at.desc())).all() |
Contributor
Author
|
Thanks. |
6 tasks
volcano303
pushed a commit
to volcano303/dify
that referenced
this pull request
Apr 7, 2026
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
HanqingZ
pushed a commit
to HanqingZ/dify
that referenced
this pull request
Apr 23, 2026
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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
db.session.query()calls to SQLAlchemy 2.xselect()style intag_service.py.first()withdb.session.scalar()+.limit(1)for single-row queries.count()withdb.session.scalar(select(func.count(...))).query().join().all()withdb.session.scalars(select().join()).all().query().outerjoin().group_by().all()withdb.session.execute(select().outerjoin().group_by()).all()Test plan
Part of #22668