mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
[mypy] Enforcing typing for superset.models (#9883)
Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
"""A collection of ORM sqlalchemy models for SQL Lab"""
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
|
||||
# pylint: disable=ungrouped-imports
|
||||
import simplejson as json
|
||||
@@ -33,6 +34,7 @@ from sqlalchemy import (
|
||||
String,
|
||||
Text,
|
||||
)
|
||||
from sqlalchemy.engine.url import URL
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
|
||||
from superset import security_manager
|
||||
@@ -99,7 +101,7 @@ class Query(Model, ExtraJSONMixin):
|
||||
|
||||
__table_args__ = (sqla.Index("ti_user_id_changed_on", user_id, changed_on),)
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"changedOn": self.changed_on,
|
||||
"changed_on": self.changed_on.isoformat(),
|
||||
@@ -130,7 +132,7 @@ class Query(Model, ExtraJSONMixin):
|
||||
}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Name property"""
|
||||
ts = datetime.now().isoformat()
|
||||
ts = ts.replace("-", "").replace(":", "").split(".")[0]
|
||||
@@ -139,11 +141,11 @@ class Query(Model, ExtraJSONMixin):
|
||||
return f"sqllab_{tab}_{ts}"
|
||||
|
||||
@property
|
||||
def database_name(self):
|
||||
def database_name(self) -> str:
|
||||
return self.database.name
|
||||
|
||||
@property
|
||||
def username(self):
|
||||
def username(self) -> str:
|
||||
return self.user.username
|
||||
|
||||
|
||||
@@ -170,7 +172,7 @@ class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin):
|
||||
)
|
||||
|
||||
@property
|
||||
def pop_tab_link(self):
|
||||
def pop_tab_link(self) -> Markup:
|
||||
return Markup(
|
||||
f"""
|
||||
<a href="/superset/sqllab?savedQueryId={self.id}">
|
||||
@@ -180,14 +182,14 @@ class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin):
|
||||
)
|
||||
|
||||
@property
|
||||
def user_email(self):
|
||||
def user_email(self) -> str:
|
||||
return self.user.email
|
||||
|
||||
@property
|
||||
def sqlalchemy_uri(self):
|
||||
def sqlalchemy_uri(self) -> URL:
|
||||
return self.database.sqlalchemy_uri
|
||||
|
||||
def url(self):
|
||||
def url(self) -> str:
|
||||
return "/superset/sqllab?savedQueryId={0}".format(self.id)
|
||||
|
||||
|
||||
@@ -226,7 +228,7 @@ class TabState(Model, AuditMixinNullable, ExtraJSONMixin):
|
||||
autorun = Column(Boolean, default=False)
|
||||
template_params = Column(Text)
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"id": self.id,
|
||||
"user_id": self.user_id,
|
||||
@@ -260,7 +262,7 @@ class TableSchema(Model, AuditMixinNullable, ExtraJSONMixin):
|
||||
|
||||
expanded = Column(Boolean, default=False)
|
||||
|
||||
def to_dict(self):
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
try:
|
||||
description = json.loads(self.description)
|
||||
except json.JSONDecodeError:
|
||||
|
||||
Reference in New Issue
Block a user