mirror of https://github.com/apache/superset.git
fix: Query execution time is displayed as invalid date (#19605)
* fix: Query execution time is displayed as invalid date * PR comment * Fix test * unify response * lint
This commit is contained in:
parent
60e06c1692
commit
e3dbe8d8af
|
@ -22,7 +22,7 @@ from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
|
|||
from superset.databases.filters import DatabaseFilter
|
||||
from superset.models.sql_lab import Query
|
||||
from superset.queries.filters import QueryFilter
|
||||
from superset.queries.schemas import openapi_spec_methods_override
|
||||
from superset.queries.schemas import openapi_spec_methods_override, QuerySchema
|
||||
from superset.views.base_api import BaseSupersetModelRestApi, RelatedFieldFilter
|
||||
from superset.views.filters import FilterRelatedOwners
|
||||
|
||||
|
@ -94,6 +94,7 @@ class QueryRestApi(BaseSupersetModelRestApi):
|
|||
]
|
||||
base_filters = [["id", QueryFilter, lambda: []]]
|
||||
base_order = ("changed_on", "desc")
|
||||
list_model_schema = QuerySchema()
|
||||
|
||||
openapi_spec_tag = "Queries"
|
||||
openapi_spec_methods = openapi_spec_methods_override
|
||||
|
|
|
@ -14,6 +14,13 @@
|
|||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from typing import List
|
||||
|
||||
from marshmallow import fields, Schema
|
||||
|
||||
from superset.dashboards.schemas import UserSchema
|
||||
from superset.models.sql_lab import Query
|
||||
from superset.sql_parse import Table
|
||||
|
||||
openapi_spec_methods_override = {
|
||||
"get": {"get": {"description": "Get query detail information."}},
|
||||
|
@ -25,3 +32,38 @@ openapi_spec_methods_override = {
|
|||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class DatabaseSchema(Schema):
|
||||
database_name = fields.String()
|
||||
|
||||
|
||||
class QuerySchema(Schema):
|
||||
"""
|
||||
Schema for the ``Query`` model.
|
||||
"""
|
||||
|
||||
changed_on = fields.DateTime()
|
||||
database = fields.Nested(DatabaseSchema)
|
||||
end_time = fields.Float(attribute="end_time")
|
||||
executed_sql = fields.String()
|
||||
id = fields.Int()
|
||||
rows = fields.Int()
|
||||
schema = fields.String()
|
||||
sql = fields.String()
|
||||
sql_tables = fields.Method("get_sql_tables")
|
||||
start_time = fields.Float(attribute="start_time")
|
||||
status = fields.String()
|
||||
tab_name = fields.String()
|
||||
tmp_table_name = fields.String()
|
||||
tracking_url = fields.String()
|
||||
user = fields.Nested(UserSchema)
|
||||
|
||||
class Meta: # pylint: disable=too-few-public-methods
|
||||
model = Query
|
||||
load_instance = True
|
||||
include_relationships = True
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def get_sql_tables(self, obj: Query) -> List[Table]:
|
||||
return obj.sql_tables
|
||||
|
|
Loading…
Reference in New Issue