-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Address regression introduced in #22853 #24121
fix: Address regression introduced in #22853 #24121
Conversation
8116d38
to
4e6930c
Compare
@@ -434,7 +463,7 @@ def get_sqla_col( | |||
expression = template_processor.process_template(expression) | |||
|
|||
sqla_col: ColumnClause = literal_column(expression) | |||
return self.table.make_sqla_column_compatible(sqla_col, label) | |||
return self.table.database.make_sqla_column_compatible(sqla_col, label) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SqlMetric
class is still tightly bound to the SqlaTable
.
Codecov Report
@@ Coverage Diff @@
## master #24121 +/- ##
==========================================
- Coverage 69.05% 69.01% -0.04%
==========================================
Files 1903 1903
Lines 74530 74522 -8
Branches 8105 8105
==========================================
- Hits 51464 51434 -30
- Misses 20955 20977 +22
Partials 2111 2111
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -1023,23 +1052,6 @@ def adhoc_column_to_sqla( # pylint: disable=too-many-locals | |||
) | |||
return self.make_sqla_column_compatible(sqla_column, label) | |||
|
|||
def make_sqla_column_compatible( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SqlaTable.make_sqla_column_compatible
method was moved to Database.make_sqla_column_compatible
given that now the TableColumn.table
variable can be None
.
return [ | ||
TableColumn( | ||
column_name=col["name"], | ||
database=self.database, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a rewrite of the previous logic using a list comprehension. The only addition is the database
argument which is required given a SQL Lab Query
object has no associated SqlaTable
which is previously were/how the database was obtained.
4e6930c
to
2f378e8
Compare
|
||
@property | ||
def type_generic(self) -> Optional[utils.GenericDataType]: | ||
if self.is_dttm: | ||
return GenericDataType.TEMPORAL | ||
|
||
bool_types = ("BOOL",) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice byproduct of this change is this previous logic can be removed given that the db_engine_spec
is accessible if associated with a Query
or SqlaTable
.
2f378e8
to
f184fdc
Compare
superset/connectors/sqla/models.py
Outdated
@@ -229,6 +230,30 @@ class TableColumn(Model, BaseColumn, CertificationMixin): | |||
update_from_object_fields = [s for s in export_fields if s not in ("table_id",)] | |||
export_parent = "table" | |||
|
|||
def __init__(self, *args: Any, **kwargs: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://docs.sqlalchemy.org/en/13/orm/constructors.html. Note I'm not overly sure if super
is necessary—it's not included in the example, but I gather it doesn't hurt.
superset/connectors/sqla/models.py
Outdated
of the ORM) depending on the context. | ||
""" | ||
|
||
self._database = kwargs.pop("database", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the database
variable isn't part of the ORM I believe I'm correct in saying that it can only be defined via a keyword argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@john-bodley is there a follow up PR where'd you be using the database
arg? also can you annotate this somehow to let people know this is going to be an ORM object vs some might assume it's an id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f184fdc
to
dcfa292
Compare
superset/connectors/sqla/models.py
Outdated
is no longer true, i.e., the SqlaTable relationship is optional. | ||
|
||
Now the TableColumn is either directly associated with the Database object ( | ||
which is unkwnonw to the ORM) or indirectly via the SqlaTable object (courtesy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unknown
925ddae
to
9c1ce2a
Compare
@@ -262,51 +287,33 @@ def is_temporal(self) -> bool: | |||
return self.is_dttm | |||
return self.type_generic == GenericDataType.TEMPORAL | |||
|
|||
@property | |||
def database(self) -> Database: | |||
return self.table.database if self.table else self._database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By design either self.table
or self._database
(but not both) will be defined and thus the database
property will always be non-null.
4251023
to
2ccf708
Compare
@hughhhh I've addressed your comments. |
2ccf708
to
e10b514
Compare
SUMMARY
Per #22853 (comment), this PR addresses an issue introduced in #22853 where chart exploration from SQL Lab would instantiate
TableColumn
objects however there was noSqlaTable
associated with said columns, which previously was a necessary requirement.This PR augments the
TableColumn
class to include aDatabase
object which is external to the ORM.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
CI and added some basic unit/integration tests.
Note there is very little unit/integration tests for this work beyond broad workflows. If people are accepting of this approach, I'll strive to add tests before merging, but I first thought there was merit to presenting this approach as a solution.
ADDITIONAL INFORMATION