Skip to content

refactor: select in tag_service#34441

Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom
RenzoMXD:refactor/select-tag-service
Apr 2, 2026
Merged

refactor: select in tag_service#34441
asukaminato0721 merged 2 commits intolanggenius:mainfrom
RenzoMXD:refactor/select-tag-service

Conversation

@RenzoMXD
Copy link
Copy Markdown
Contributor

@RenzoMXD RenzoMXD commented Apr 2, 2026

Summary

  • Migrate all 9 db.session.query() calls to SQLAlchemy 2.x select() style in tag_service.py
  • Replace .first() with db.session.scalar() + .limit(1) for single-row queries
  • Replace .count() with db.session.scalar(select(func.count(...)))
  • Replace .query().join().all() with db.session.scalars(select().join()).all()
  • Replace .query().outerjoin().group_by().all() with db.session.execute(select().outerjoin().group_by()).all()
  • No test changes needed

Test plan

  • All 10 unit tests pass for tag controller tests
  • Type checks pass (basedpyright + pyrefly + mypy)

Part of #22668

@RenzoMXD RenzoMXD requested a review from QuantumGhost as a code owner April 2, 2026 04:45
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Apr 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

Pyrefly Diff

No changes detected.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

Pyrefly Diff

No changes detected.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 2, 2026
@asukaminato0721 asukaminato0721 requested a review from Copilot April 2, 2026 05:04
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 in TagService to select(...) statements.
  • Replaced .first() / .count() patterns with db.session.scalar(...) and select(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())
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

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()

Copilot uses AI. Check for mistakes.
Merged via the queue into langgenius:main with commit cb9ee59 Apr 2, 2026
30 of 31 checks passed
@RenzoMXD RenzoMXD deleted the refactor/select-tag-service branch April 2, 2026 11:13
@RenzoMXD
Copy link
Copy Markdown
Contributor Author

RenzoMXD commented Apr 2, 2026

Thanks.

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>
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.

3 participants