GitHub user FrancescoCastaldi added a comment to the discussion: import
dashboard
This issue occurs because when dashboards are imported from a ZIP/YAML export,
the dataset metadata (physical database column types, calculated metrics, and
temporal flags) is imported from the export schema, but the underlying database
connection in the target environment has not yet synchronized column types with
the target database engine.
When you click "Edit Dataset" and then "Save", Superset triggers
`UpdateDatasetCommand` / `sync_columns()`, which re-queries the database
metadata via SQLAlchemy and populates `table_columns` and `sql_metrics`.
### How to synchronize all datasets in bulk
You do not need to edit them manually one by one. You can automate this using
either the Superset CLI or a short Python administrative script.
#### Method 1: Administrative CLI Command
Execute the `refresh-datasources` CLI command inside your Superset container or
virtual environment:
```bash
# In Docker Compose
docker compose exec superset superset refresh-datasources
# Or targeting a specific database connection
docker compose exec superset superset refresh-datasources --database-name
"YourDatabase"
```
#### Method 2: Python Script (Bulk Refresh via Superset App Context)
Run this script inside the Superset container using `superset shell` or
`python`:
```python
from superset.app import create_app
app = create_app()
with app.app_context():
from superset import db
from superset.connectors.sqla.models import SqlaTable
datasets = db.session.query(SqlaTable).all()
print(f"Syncing metadata for {len(datasets)} datasets...")
for ds in datasets:
try:
ds.fetch_metadata()
print(f"Successfully refreshed: {ds.table_name} (ID: {ds.id})")
except Exception as e:
print(f"Error refreshing {ds.table_name}: {e}")
db.session.commit()
print("Bulk metadata sync complete.")
```
#### Method 3: REST API Refresh Loop
If you prefer using the REST API from CI/CD, call the refresh endpoint for each
dataset ID:
```bash
# Obtain your JWT token via /api/v1/security/login, then:
curl -X POST "http://localhost:8088/api/v1/dataset/<DATASET_ID>/refresh" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
```
Running either Method 1 or 2 will synchronize all columns and metrics across
all imported datasets at once.
GitHub link:
https://github.com/apache/superset/discussions/41337#discussioncomment-19164771
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]