bito-code-review[bot] commented on PR #41106:
URL: https://github.com/apache/superset/pull/41106#issuecomment-4745131592
<!-- Bito Reply -->
The suggested approach is a robust improvement over manually copying
individual fields, as it leverages the model's existing structure to ensure new
fields are automatically included. This pattern is generally preferred in
SQLAlchemy-based models to maintain consistency and reduce maintenance overhead
when the model schema evolves. Applying this change is recommended to make the
duplication logic more resilient.
**superset/commands/dataset/duplicate.py**
```
table = self._base_model.copy() # copies all `export_fields`
table.table_name = table_name # override the cloned name
table.owners = owners
table.database = database
table.is_sqllab_view = True
if table.sql:
table.sql = table.sql.strip().strip(";")
db.session.add(table)
table.columns = [
TableColumn(
column_name=c.column_name,
verbose_name=c.verbose_name,
expression=c.expression,
filterable=True,
groupby=True,
is_dttm=c.is_dttm,
type=c.type,
description=c.description,
)
for c in self._base_model.columns
]
table.metrics = [
SqlMetric(
metric_name=m.metric_name,
verbose_name=m.verbose_name,
expression=m.expression,
metric_type=m.metric_type,
description=m.description,
)
for m in self._base_model.metrics
]
return table
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]