mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
fix: remove .query reference of db.Model
This commit is contained in:
parent
bedbd658fe
commit
53e1b45d40
|
@ -1,6 +1,8 @@
|
||||||
import flask_restful
|
import flask_restful
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from flask_restful import Resource, fields, marshal_with
|
from flask_restful import Resource, fields, marshal_with
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
|
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
|
@ -25,7 +27,13 @@ api_key_list = {"data": fields.List(fields.Nested(api_key_fields), attribute="it
|
||||||
|
|
||||||
|
|
||||||
def _get_resource(resource_id, tenant_id, resource_model):
|
def _get_resource(resource_id, tenant_id, resource_model):
|
||||||
resource = resource_model.query.filter_by(id=resource_id, tenant_id=tenant_id).first()
|
if resource_model == App:
|
||||||
|
with Session(db.engine) as session:
|
||||||
|
resource = session.execute(
|
||||||
|
select(resource_model).filter_by(id=resource_id, tenant_id=tenant_id)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
else:
|
||||||
|
resource = resource_model.query.filter_by(id=resource_id, tenant_id=tenant_id).first()
|
||||||
|
|
||||||
if resource is None:
|
if resource is None:
|
||||||
flask_restful.abort(404, message=f"{resource_model.__name__} not found.")
|
flask_restful.abort(404, message=f"{resource_model.__name__} not found.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user