You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/06/07 22:48:55 UTC

[GitHub] john-bodley closed pull request #5161: [migration] Adding migration to remove empty in/not-in filters

john-bodley closed pull request #5161: [migration] Adding migration to remove empty in/not-in filters
URL: https://github.com/apache/incubator-superset/pull/5161
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/migrations/versions/afb7730f6a9c_remove_empty_filters.py b/superset/migrations/versions/afb7730f6a9c_remove_empty_filters.py
new file mode 100644
index 0000000000..1995a52f92
--- /dev/null
+++ b/superset/migrations/versions/afb7730f6a9c_remove_empty_filters.py
@@ -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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org