serenajiang commented on a change in pull request #10630:
URL:
https://github.com/apache/incubator-superset/pull/10630#discussion_r472485667
##########
File path: superset/connectors/sqla/models.py
##########
@@ -391,6 +394,38 @@ def lookup_obj(lookup_metric: SqlMetric) -> SqlMetric:
return import_datasource.import_simple_obj(db.session, i_metric,
lookup_obj)
+ @property
+ def is_certified(self) -> bool:
+ try:
+ extra_object = json.loads(self.extra)
+ return bool(extra_object.get("certification", False))
+ except (TypeError, json.JSONDecodeError):
+ return False
+
+ @property
+ def certified_by(self) -> Optional[str]:
+ try:
+ extra_object = json.loads(self.extra)
+ return extra_object.get("certification", {}).get("certified_by",
None)
Review comment:
```suggestion
return extra_object.get("certification", {}).get("certified_by")
```
🐍
##########
File path: superset/connectors/sqla/models.py
##########
@@ -391,6 +394,38 @@ def lookup_obj(lookup_metric: SqlMetric) -> SqlMetric:
return import_datasource.import_simple_obj(db.session, i_metric,
lookup_obj)
+ @property
+ def is_certified(self) -> bool:
+ try:
+ extra_object = json.loads(self.extra)
+ return bool(extra_object.get("certification", False))
+ except (TypeError, json.JSONDecodeError):
+ return False
+
+ @property
+ def certified_by(self) -> Optional[str]:
+ try:
+ extra_object = json.loads(self.extra)
+ return extra_object.get("certification", {}).get("certified_by",
None)
+ except (TypeError, json.JSONDecodeError):
+ return None
+
+ @property
+ def certification_details(self) -> Optional[str]:
+ try:
+ extra_object = json.loads(self.extra)
+ return extra_object.get("certification", {}).get("details", None)
Review comment:
```suggestion
return extra_object.get("certification", {}).get("details")
```
🐍
##########
File path: superset/connectors/sqla/models.py
##########
@@ -391,6 +394,38 @@ def lookup_obj(lookup_metric: SqlMetric) -> SqlMetric:
return import_datasource.import_simple_obj(db.session, i_metric,
lookup_obj)
+ @property
+ def is_certified(self) -> bool:
+ try:
+ extra_object = json.loads(self.extra)
+ return bool(extra_object.get("certification", False))
Review comment:
```suggestion
return bool(extra_object.get("certification"))
```
🐍
##########
File path: superset/connectors/sqla/models.py
##########
@@ -391,6 +394,38 @@ def lookup_obj(lookup_metric: SqlMetric) -> SqlMetric:
return import_datasource.import_simple_obj(db.session, i_metric,
lookup_obj)
+ @property
+ def is_certified(self) -> bool:
+ try:
+ extra_object = json.loads(self.extra)
+ return bool(extra_object.get("certification", False))
+ except (TypeError, json.JSONDecodeError):
+ return False
+
+ @property
+ def certified_by(self) -> Optional[str]:
+ try:
+ extra_object = json.loads(self.extra)
+ return extra_object.get("certification", {}).get("certified_by",
None)
+ except (TypeError, json.JSONDecodeError):
+ return None
+
+ @property
+ def certification_details(self) -> Optional[str]:
+ try:
+ extra_object = json.loads(self.extra)
+ return extra_object.get("certification", {}).get("details", None)
+ except (TypeError, json.JSONDecodeError):
+ return None
+
+ @property
+ def data(self) -> Dict[str, Any]:
+ attrs = ("is_certified", "certified_by", "certification_details")
+ attr_dict = {s: getattr(self, s) for s in attrs}
Review comment:
It's a little weird that we have these related attributes floating
around as separate attributes in the `attr_dict`. Does `data` need to be a flat
dict, or can we keep these all in one "certification" object, sorta like how
they're stored in `extra`? So, `.data` could return
```python
{
"certification": {
"is_certified": ...,
"certified_by": ...,
"certification_details": ...
},
...
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]