Skip to content

Commit

Permalink
Revert "fix(sqllab): throw errors of commented out query (#23378)"
Browse files Browse the repository at this point in the history
This reverts commit d1947f7.
  • Loading branch information
justinpark committed May 10, 2023
1 parent fdd69d3 commit 67ac8e8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 34 deletions.
10 changes: 1 addition & 9 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,6 @@ export function fetchQueryResults(query, displayLimit) {
};
}

export function cleanSqlComments(sql) {
if (!sql) return '';
// it sanitizes the following comment block groups
// group 1 -> /* */
// group 2 -> --
return sql.replace(/(--.*?$|\/\*[\s\S]*?\*\/)\n?/gm, '\n').trim();
}

export function runQuery(query) {
return function (dispatch) {
dispatch(startQuery(query));
Expand All @@ -374,7 +366,7 @@ export function runQuery(query) {
json: true,
runAsync: query.runAsync,
schema: query.schema,
sql: cleanSqlComments(query.sql),
sql: query.sql,
sql_editor_id: query.sqlEditorId,
tab: query.tab,
tmp_table_name: query.tempTable,
Expand Down
23 changes: 0 additions & 23 deletions superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,29 +308,6 @@ describe('async actions', () => {
});
});

describe('runQuery with comments', () => {
const makeRequest = () => {
const request = actions.runQuery({
...query,
sql: '/*\nSELECT * FROM\n */\nSELECT 213--, {{ds}}\n/*\n{{new_param1}}\n{{new_param2}}*/\n\nFROM table',
});
return request(dispatch, () => initialState);
};

it('makes the fetch request without comments', async () => {
const runQueryEndpoint = 'glob:*/api/v1/sqllab/execute/';
fetchMock.post(runQueryEndpoint, '{}', {
overwriteRoutes: true,
});
await makeRequest().then(() => {
expect(fetchMock.calls(runQueryEndpoint)).toHaveLength(1);
expect(
JSON.parse(fetchMock.calls(runQueryEndpoint)[0][1].body).sql,
).toEqual('SELECT 213\n\n\nFROM table');
});
});
});

describe('reRunQuery', () => {
let stub;
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { DropdownButton } from 'src/components/DropdownButton';
import { detectOS } from 'src/utils/common';
import { QueryButtonProps } from 'src/SqlLab/types';
import useQueryEditor from 'src/SqlLab/hooks/useQueryEditor';
import { cleanSqlComments } from 'src/SqlLab/actions/sqlLab';

export interface RunQueryActionButtonProps {
queryEditorId: string;
Expand Down Expand Up @@ -106,7 +105,9 @@ const RunQueryActionButton = ({
: Button;

const sqlContent = selectedText || sql || '';
const isDisabled = cleanSqlComments(sqlContent).length === 0;
const isDisabled =
!sqlContent ||
!sqlContent.replace(/(\/\*[^*]*\*\/)|(\/\/[^*]*)|(--[^.].*)/gm, '').trim();

const stopButtonTooltipText = useMemo(
() =>
Expand Down

0 comments on commit 67ac8e8

Please sign in to comment.