dosubot[bot] commented on issue #29909:
URL: https://github.com/apache/superset/issues/29909#issuecomment-2278890061

   <!-- Greeting -->
   @nicmrayce Hello there! I'm here to help you with any bugs, questions, or 
contributions you have for the repository. Let's work together to solve this 
issue.
   
   <!-- Answer -->
   To resolve the issue where filters on all dashboards are non-functional 
after migrating to the latest version of Superset, with selected values 
appearing as null, you need to ensure that the filter sets are correctly 
migrated to the new format. The provided migration script 
`migrate_native_filters_to_new_schema.py` handles this process.
   
   Here is the relevant part of the migration script that upgrades the filter 
sets:
   
   ```python
   def upgrade():
       bind = op.get_bind()
       session = db.Session(bind=bind)
   
       dashboards = (
           session.query(Dashboard)
           
.filter(Dashboard.json_metadata.like('%"native_filter_configuration"%'))
           .all()
       )
       changed_filters, changed_filter_sets = 0, 0
       for dashboard in dashboards:
           try:
               json_metadata = json.loads(dashboard.json_metadata)
               dashboard.json_metadata = json.dumps(json_metadata, 
sort_keys=True)
   
               upgrades = upgrade_dashboard(json_metadata)
               changed_filters += upgrades[0]
               changed_filter_sets += upgrades[1]
               dashboard.json_metadata = json.dumps(json_metadata, 
sort_keys=True)
           except Exception:
               print(f"Parsing json_metadata for dashboard {dashboard.id} 
failed.")
               raise
   
       session.commit()
       session.close()
       print(f"Upgraded {changed_filters} filters and {changed_filter_sets} 
filter sets.")
   ```
   
   Additionally, you should also run the migration script `cleanup erroneous 
parent filter IDs` to ensure that any erroneous parent filter IDs are cleaned 
up. This script is crucial for maintaining the integrity of the filter 
configurations.
   
   Here is the relevant part of the script:
   
   ```python
   def upgrade():
       bind = op.get_bind()
       session = db.Session(bind=bind)
   
       for dashboard in session.query(Dashboard).all():
           if dashboard.json_metadata:
               updated = False
   
               try:
                   json_metadata = json.loads(dashboard.json_metadata)
   
                   if filters := 
json_metadata.get("native_filter_configuration"):
                       filter_ids = {fltr["id"] for fltr in filters}
   
                       for fltr in filters:
                           for parent_id in fltr.get("cascadeParentIds", [])[:]:
                               if parent_id not in filter_ids:
                                   fltr["cascadeParentIds"].remove(parent_id)
                                   updated = True
   
                   if updated:
                       dashboard.json_metadata = json.dumps(json_metadata)
               except Exception:
                   logging.exception(
                       f"Unable to parse JSON metadata for dashboard 
{dashboard.id}"
                   )
   
       session.commit()
       session.close()
   ```
   
   Ensure that both migration scripts have been executed successfully. If the 
problem persists, you may need to manually verify that the `json_metadata` of 
your dashboards has been correctly updated according to the new format 
specified in the scripts 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/migrations/versions/2021-04-12_12-38_fc3a3a8ff221_migrate_filter_sets_to_new_format.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset/migrations/versions/2023-07-19_16-48_a23c6f8b1280_cleanup_erroneous_parent_filter_ids.py)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset/migrations/versions/2021-04-29_15-32_f1410ed7ec95_migrate_native_filters_to_new_schema.py)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
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]

Reply via email to