|
2 | 2 | from flask import request |
3 | 3 | from flask_login import current_user |
4 | 4 | from flask_restx import Resource, marshal, marshal_with, reqparse |
| 5 | +from sqlalchemy import select |
5 | 6 | from werkzeug.exceptions import Forbidden, NotFound |
6 | 7 |
|
7 | 8 | import services |
@@ -411,11 +412,11 @@ def post(self): |
411 | 412 | extract_settings = [] |
412 | 413 | if args["info_list"]["data_source_type"] == "upload_file": |
413 | 414 | file_ids = args["info_list"]["file_info_list"]["file_ids"] |
414 | | - file_details = ( |
415 | | - db.session.query(UploadFile) |
416 | | - .where(UploadFile.tenant_id == current_user.current_tenant_id, UploadFile.id.in_(file_ids)) |
417 | | - .all() |
418 | | - ) |
| 415 | + file_details = db.session.scalars( |
| 416 | + select(UploadFile).where( |
| 417 | + UploadFile.tenant_id == current_user.current_tenant_id, UploadFile.id.in_(file_ids) |
| 418 | + ) |
| 419 | + ).all() |
419 | 420 |
|
420 | 421 | if file_details is None: |
421 | 422 | raise NotFound("File not found.") |
@@ -518,11 +519,11 @@ class DatasetIndexingStatusApi(Resource): |
518 | 519 | @account_initialization_required |
519 | 520 | def get(self, dataset_id): |
520 | 521 | dataset_id = str(dataset_id) |
521 | | - documents = ( |
522 | | - db.session.query(Document) |
523 | | - .where(Document.dataset_id == dataset_id, Document.tenant_id == current_user.current_tenant_id) |
524 | | - .all() |
525 | | - ) |
| 522 | + documents = db.session.scalars( |
| 523 | + select(Document).where( |
| 524 | + Document.dataset_id == dataset_id, Document.tenant_id == current_user.current_tenant_id |
| 525 | + ) |
| 526 | + ).all() |
526 | 527 | documents_status = [] |
527 | 528 | for document in documents: |
528 | 529 | completed_segments = ( |
@@ -569,11 +570,11 @@ class DatasetApiKeyApi(Resource): |
569 | 570 | @account_initialization_required |
570 | 571 | @marshal_with(api_key_list) |
571 | 572 | def get(self): |
572 | | - keys = ( |
573 | | - db.session.query(ApiToken) |
574 | | - .where(ApiToken.type == self.resource_type, ApiToken.tenant_id == current_user.current_tenant_id) |
575 | | - .all() |
576 | | - ) |
| 573 | + keys = db.session.scalars( |
| 574 | + select(ApiToken).where( |
| 575 | + ApiToken.type == self.resource_type, ApiToken.tenant_id == current_user.current_tenant_id |
| 576 | + ) |
| 577 | + ).all() |
577 | 578 | return {"items": keys} |
578 | 579 |
|
579 | 580 | @setup_required |
|
0 commit comments