Skip to content

Commit

Permalink
Deprecate npm run backend-sync and related logic (#7211)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Apr 10, 2019
1 parent 6c38cb1 commit 0c3e46f
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 137 deletions.
3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,6 @@ npm run dev

# Compile the Javascript and CSS in production/optimized mode for official releases
npm run prod

# Copy a conf file from the frontend to the backend
npm run sync-backend
```

#### Updating NPM packages
Expand Down
1 change: 1 addition & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ assists people when migrating to a new version.

## Superset 0.32.0

* `npm run backend-sync` is deprecated and no longer needed, will fail if called
* [5445](https://github.com/apache/incubator-superset/pull/5445) : a change
which prevents encoding of empty string from form data in the datanbase.
This involves a non-schema changing migration which does potentially impact
Expand Down
1 change: 0 additions & 1 deletion contrib/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ USER superset

RUN cd superset/assets \
&& npm ci \
&& npm run sync-backend \
&& npm run build \
&& rm -rf node_modules

Expand Down
2 changes: 1 addition & 1 deletion contrib/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [ "$#" -ne 0 ]; then
elif [ "$SUPERSET_ENV" = "development" ]; then
celery worker --app=superset.sql_lab:celery_app --pool=gevent -Ofair &
# needed by superset runserver
(cd superset/assets/ && npm ci && npm run sync-backend)
(cd superset/assets/ && npm ci)
(cd superset/assets/ && npm run dev) &
FLASK_ENV=development FLASK_APP=superset:app flask run -p 8088 --with-threads --reload --debugger --host=0.0.0.0
elif [ "$SUPERSET_ENV" = "production" ]; then
Expand Down
3 changes: 0 additions & 3 deletions superset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
if not os.path.exists(config.DATA_DIR):
os.makedirs(config.DATA_DIR)

with open(APP_DIR + '/static/assets/backendSync.json', 'r', encoding='utf-8') as f:
frontend_config = json.load(f)

app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
conf = app.config
Expand Down
1 change: 0 additions & 1 deletion superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"build": "NODE_ENV=production webpack --mode=production --colors --progress",
"lint": "eslint --ignore-path=.eslintignore --ext .js,.jsx . && tslint -c tslint.json ./{src,spec}/**/*.ts{,x}",
"lint-fix": "eslint --fix --ignore-path=.eslintignore --ext .js,.jsx . && tslint -c tslint.json --fix ./{src,spec}/**/*.ts{,x}",
"sync-backend": "babel-node --preset=@babel/preset-env src/syncBackend.js",
"cypress": "cypress",
"cypress-debug": "cypress open --config watchForFileChanges=true",
"install-cypress": "npm install cypress@3.1.5"
Expand Down
43 changes: 0 additions & 43 deletions superset/assets/src/syncBackend.js

This file was deleted.

76 changes: 0 additions & 76 deletions superset/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,82 +16,6 @@
# under the License.
# pylint: disable=C,R,W
"""Code related with dealing with legacy / change management"""
import re

from superset import frontend_config

FORM_DATA_KEY_WHITELIST = list(frontend_config.get('controls').keys()) + ['slice_id']


def cast_filter_data(form_data):
"""Used by cast_form_data to parse the filters"""
flts = []
having_flts = []
fd = form_data
filter_pattern = re.compile(r"""((?:[^,"']|"[^"]*"|'[^']*')+)""")
for i in range(0, 10):
for prefix in ['flt', 'having']:
col_str = '{}_col_{}'.format(prefix, i)
op_str = '{}_op_{}'.format(prefix, i)
val_str = '{}_eq_{}'.format(prefix, i)
if col_str in fd and op_str in fd and val_str in fd \
and len(fd[val_str]) > 0:
f = {}
f['col'] = fd[col_str]
f['op'] = fd[op_str]
if prefix == 'flt':
# transfer old strings in filter value to list
splitted = filter_pattern.split(fd[val_str])[1::2]
values = [types.replace("'", '').strip() for types in splitted]
f['val'] = values
flts.append(f)
if prefix == 'having':
f['val'] = fd[val_str]
having_flts.append(f)
if col_str in fd:
del fd[col_str]
if op_str in fd:
del fd[op_str]
if val_str in fd:
del fd[val_str]
fd['filters'] = flts
fd['having_filters'] = having_flts
return fd


def cast_form_data(form_data):
"""Translates old to new form_data"""
d = {}
fields = frontend_config.get('controls', {})
for k, v in form_data.items():
field_config = fields.get(k, {})
ft = field_config.get('type')
if ft == 'CheckboxControl':
# bug in some urls with dups on bools
if isinstance(v, list):
v = 'y' in v
else:
v = True if v in ('true', 'y') or v is True else False
elif v and ft == 'TextControl' and field_config.get('isInt'):
v = int(v) if v != '' else None
elif v and ft == 'TextControl' and field_config.get('isFloat'):
v = float(v) if v != '' else None
elif v and ft == 'SelectControl':
if field_config.get('multi'):
if type(form_data).__name__ == 'ImmutableMultiDict':
v = form_data.getlist(k)
elif not isinstance(v, list):
v = [v]
if d.get('slice_id'):
d['slice_id'] = int(d['slice_id'])

d[k] = v
if 'filters' not in d:
d = cast_filter_data(d)
for k in list(d.keys()):
if k not in FORM_DATA_KEY_WHITELIST:
del d[k]
return d


def update_time_range(form_data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import json
import sqlalchemy as sa
from superset import db
from superset.legacy import cast_form_data
from sqlalchemy.ext.declarative import declarative_base
from urllib import parse

Expand Down Expand Up @@ -72,7 +71,6 @@ def upgrade():
d = parse_querystring(url.url.split('?')[1])
split = url.url.split('/')
d['datasource'] = split[5] + '__' + split[4]
d = cast_form_data(d)
newurl = '/'.join(split[:-1]) + '/?form_data=' + parse.quote_plus(json.dumps(d))
url.url = newurl
session.merge(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from sqlalchemy import Column, Integer, String, Text

from superset import db
from superset.legacy import cast_form_data

Base = declarative_base()

Expand All @@ -55,7 +54,6 @@ def upgrade():
for i, slc in enumerate(slices):
try:
d = json.loads(slc.params or '{}')
d = cast_form_data(d)
slc.params = json.dumps(d, indent=2, sort_keys=True)
session.merge(slc)
session.commit()
Expand Down
6 changes: 1 addition & 5 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from superset.exceptions import SupersetException
from superset.forms import CsvToDatabaseForm
from superset.jinja_context import get_template_processor
from superset.legacy import cast_form_data, update_time_range
from superset.legacy import update_time_range
import superset.models.core as models
from superset.models.sql_lab import Query
from superset.models.user_attributes import UserAttribute
Expand Down Expand Up @@ -1058,10 +1058,6 @@ def get_form_data(self, slice_id=None, use_slice_data=False):
url_form_data.update(form_data)
form_data = url_form_data

if request.args.get('viz_type'):
# Converting old URLs
form_data = cast_form_data(form_data)

form_data = {
k: v
for k, v in form_data.items()
Expand Down

0 comments on commit 0c3e46f

Please sign in to comment.