code: def upgrade():
      bind = op.get_bind()
      session = db.Session(bind=bind)
  
      for slc in session.query(Slice).all():
          if slc.params:
              updated = False
  
              try:
                  params = json.loads(slc.params)
  
                  for key in ["druid_time_origin", "granularity"]:
                      if key in params:
                          del params[key]
                          updated = True
  
                  if updated:
                      slc.params = json.dumps(params)
              except Exception:
                  logging.exception(
                      f"Unable to parse params for slice {slc.id}"
                  )
  
          if slc.query_context:
              updated = False
  
              try:
                  query_context = json.loads(slc.query_context)
  
                  if form_data := query_context.get("form_data"):
                      for key in ["druid_time_origin", "granularity"]:
                          if key in form_data:
                              del form_data[key]
                              updated = True
  
                  for query in query_context.get("queries", []):
                      for key in ["druid_time_origin", "granularity"]:
                          if key in query:
                              del query[key]
                              updated = True
  
                      if extras := query.get("extras"):
                          if "having_druid" in extras:
                              del extras["having_druid"]
                              updated = True
  
                  if updated:
                      slc.query_context = json.dumps(query_context)
              except Exception:
                  logging.exception(
                      f"Unable to parse query context for slice {slc.id}"
                  )
  
      session.commit()
      session.close()
  
file_path: superset/superset/migrations/versions/2023-07-18_15-30_863adcf72773_delete_obsolete_druid_nosql_slice_parameters.py
imports: import json
  import logging
  from alembic import op
  from sqlalchemy import Column, Integer, Text
  from sqlalchemy.ext.declarative import declarative_base
  from superset import db
label_desc: Use image node_id 1 for calling a global function with example usage: upgrade() without return types