code: def upgrade():
      """
      Remove any erroneous time granularity fields from slices foor those visualization
      types which do not support time granularity.
  
      :see: https://github.com/apache/superset/pull/8674
      :see: https://github.com/apache/superset/pull/8764
      :see: https://github.com/apache/superset/pull/8800
      :see: https://github.com/apache/superset/pull/8825
      """
  
      bind = op.get_bind()
      session = db.Session(bind=bind)
  
      # Visualization types which support time granularity (hence negate).
      viz_types = [
          "area",
          "bar",
          "big_number",
          "compare",
          "dual_line",
          "line",
          "pivot_table",
          "table",
          "time_pivot",
          "time_table",
      ]
  
      # Erroneous time granularity fields for either Druid NoSQL or SQL slices which do
      # not support time granularity.
      erroneous = ["granularity", "time_grain_sqla"]
  
      for slc in (
          session.query(Slice)
          .filter(Slice.viz_type.notin_(viz_types))
          .all()
      ):
          try:
              params = json.loads(slc.params)
  
              if any(field in params for field in erroneous):
                  for field in erroneous:
                      if field in params:
                          del params[field]
  
                  slc.params = json.dumps(params, sort_keys=True)
          except Exception:
              pass
  
      session.commit()
      session.close()
  
file_path: superset/superset/migrations/versions/2020-03-25_10-42_f9a30386bd74_cleanup_time_grainularity.py
imports: import json
  from alembic import op
  from sqlalchemy import Column, Integer, String, 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