You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jo...@apache.org on 2018/06/07 22:49:04 UTC
[incubator-superset] branch master updated: [migration] Adding
migration to remove empty in/not-in filters (#5161)
This is an automated email from the ASF dual-hosted git repository.
johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 1b4406d [migration] Adding migration to remove empty in/not-in filters (#5161)
1b4406d is described below
commit 1b4406db3f878ac418fc239af03ab76f3b9f20c0
Author: John Bodley <45...@users.noreply.github.com>
AuthorDate: Thu Jun 7 15:48:53 2018 -0700
[migration] Adding migration to remove empty in/not-in filters (#5161)
---
.../versions/afb7730f6a9c_remove_empty_filters.py | 57 ++++++++++++++++++++++
1 file changed, 57 insertions(+)
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 0000000..1995a52
--- /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
--
To stop receiving notification emails like this one, please contact
johnbodley@apache.org.