dpgaspar commented on a change in pull request #13389:
URL: https://github.com/apache/superset/pull/13389#discussion_r587374293
##########
File path: superset/datasets/dao.py
##########
@@ -186,9 +169,77 @@ def update( # pylint: disable=W:279
super().update(model, properties, commit=commit)
properties["columns"] = original_properties
- super().update(model, properties, commit=False)
+ updated_model = super().update(model, properties, commit=False)
model.health_check(force=True, commit=False)
- return super().update(model, properties, commit=commit)
+ return updated_model
+
+ @classmethod
+ def update_columns(
+ cls,
+ model: SqlaTable,
+ property_columns: List[Dict[str, Any]],
+ commit: bool = True,
+ ) -> List[TableColumn]:
+ """
+ Creates/updates and/or deletes a list of columns, based on a
+ list of Dict.
+
+ - If a column Dict has an `id` property then we update.
+ - If a column Dict does not have an `id` then we create a new metric.
+ - If there are extra columns on the metadata db that are not defined
on the List
+ then we delete.
+ """
+ new_columns = []
+ for column in property_columns:
+ column_id = column.get("id")
+
+ if column_id:
+ column_obj = db.session.query(TableColumn).get(column_id)
+ column_obj = DatasetDAO.update_column(column_obj, column,
commit=commit)
+ else:
+ column_obj = DatasetDAO.create_column(column, commit=commit)
+ new_columns.append(column_obj)
+ # Checks if an exiting column is missing from properties and delete it
+ for existing_column in model.columns:
+ if existing_column.column_name not in [
+ column["column_name"] for column in property_columns
Review comment:
good catch, changed
----------------------------------------------------------------
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]