Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
[migration] Adding migration to remove empty in/not-in filters (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Jun 7, 2018
1 parent 5b35f75 commit 1b4406d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions superset/migrations/versions/afb7730f6a9c_remove_empty_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""remove empty filters
Revision ID: afb7730f6a9c
Revises: c5756bec8b47
Create Date: 2018-06-07 09:52:54.535961
"""

# revision identifiers, used by Alembic.
revision = 'afb7730f6a9c'
down_revision = 'c5756bec8b47'

from alembic import op
import json
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Text

from superset import db

Base = declarative_base()


class Slice(Base):
__tablename__ = 'slices'

id = Column(Integer, primary_key=True)
params = Column(Text)


def upgrade():
bind = op.get_bind()
session = db.Session(bind=bind)

for slc in session.query(Slice).all():
try:
params = json.loads(slc.params)

for key in ('filters', 'having_filters', 'extra_filters'):
value = params.get(key)

# Remove empty in/not-in filters.
if value:
params[key] = [
x for x in value
if not (x['op'] in ('in', 'not in') and not x['val'])
]

slc.params = json.dumps(params, sort_keys=True)
except Exception:
pass

session.commit()
session.close()


def downgrade():
pass

0 comments on commit 1b4406d

Please sign in to comment.