Skip to content
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: make dataset update methods static instead of global #16044

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,25 +1690,25 @@ def external_metadata(self) -> List[Dict[str, Any]]:
latest_metadata = self.latest_metadata() or {}
return [{"name": k, "type": v.get("type")} for k, v in latest_metadata.items()]

@staticmethod
def update_datasource(
_mapper: Mapper, _connection: Connection, obj: Union[DruidColumn, DruidMetric]
) -> None:
"""
Forces an update to the datasource's changed_on value when a metric or column on
the datasource is updated. This busts the cache key for all charts that use the
datasource.

def update_datasource(
_mapper: Mapper, _connection: Connection, obj: Union[DruidColumn, DruidMetric]
) -> None:
"""
Forces an update to the datasource's changed_on value when a metric or column on
the datasource is updated. This busts the cache key for all charts that use the
datasource.

:param _mapper: Unused.
:param _connection: Unused.
:param obj: The metric or column that was updated.
"""
db.session.execute(
update(DruidDatasource).where(DruidDatasource.id == obj.datasource.id)
)
:param _mapper: Unused.
:param _connection: Unused.
:param obj: The metric or column that was updated.
"""
db.session.execute(
update(DruidDatasource).where(DruidDatasource.id == obj.datasource.id)
)


sa.event.listen(DruidDatasource, "after_insert", security_manager.set_perm)
sa.event.listen(DruidDatasource, "after_update", security_manager.set_perm)
sa.event.listen(DruidMetric, "after_update", update_datasource)
sa.event.listen(DruidColumn, "after_update", update_datasource)
sa.event.listen(DruidMetric, "after_update", DruidDatasource.update_datasource)
sa.event.listen(DruidColumn, "after_update", DruidDatasource.update_datasource)
28 changes: 14 additions & 14 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,26 +1653,26 @@ def before_update(
):
raise Exception(get_dataset_exist_error_msg(target.full_name))

@staticmethod
def update_table(
_mapper: Mapper, _connection: Connection, obj: Union[SqlMetric, TableColumn]
) -> None:
"""
Forces an update to the table's changed_on value when a metric or column on the
table is updated. This busts the cache key for all charts that use the table.

def update_table(
_mapper: Mapper, _connection: Connection, obj: Union[SqlMetric, TableColumn]
) -> None:
"""
Forces an update to the table's changed_on value when a metric or column on the
table is updated. This busts the cache key for all charts that use the table.

:param _mapper: Unused.
:param _connection: Unused.
:param obj: The metric or column that was updated.
"""
db.session.execute(update(SqlaTable).where(SqlaTable.id == obj.table.id))
:param _mapper: Unused.
:param _connection: Unused.
:param obj: The metric or column that was updated.
"""
db.session.execute(update(SqlaTable).where(SqlaTable.id == obj.table.id))


sa.event.listen(SqlaTable, "after_insert", security_manager.set_perm)
sa.event.listen(SqlaTable, "after_update", security_manager.set_perm)
sa.event.listen(SqlaTable, "before_update", SqlaTable.before_update)
sa.event.listen(SqlMetric, "after_update", update_table)
sa.event.listen(TableColumn, "after_update", update_table)
sa.event.listen(SqlMetric, "after_update", SqlaTable.update_table)
sa.event.listen(TableColumn, "after_update", SqlaTable.update_table)

RLSFilterRoles = Table(
"rls_filter_roles",
Expand Down