From e38c38cd581ceaa8c45b622b9bf37204caca9d59 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Wed, 12 Jan 2022 14:53:19 +0530 Subject: [PATCH] Fixed following SonarQube code smells: 1) Remove this useless assignment to a variable. 2) Remove the unused local variable. --- web/pgadmin/__init__.py | 15 +++++++-------- web/pgadmin/authenticate/webserver.py | 2 +- .../server_groups/servers/roles/__init__.py | 5 +---- .../browser/server_groups/servers/utils.py | 2 +- .../pg_utilities_backup_restore_test.py | 4 +--- .../pg_utilities_maintenance_test.py | 2 +- web/pgadmin/misc/file_manager/__init__.py | 2 +- web/pgadmin/misc/themes/__init__.py | 2 +- web/pgadmin/static/js/SchemaView/index.jsx | 9 ++------- web/pgadmin/tools/erd/tests/test_tables.py | 2 +- .../tools/import_export_servers/__init__.py | 2 +- web/pgadmin/tools/psql/__init__.py | 2 +- .../tools/sqleditor/static/js/sqleditor.js | 13 ++++++------- .../tools/sqleditor/utils/save_changed_data.py | 2 +- web/pgadmin/utils/master_password.py | 4 ++-- web/regression/feature_utils/pgadmin_page.py | 2 +- web/regression/python_test_utils/test_utils.py | 2 +- 17 files changed, 30 insertions(+), 42 deletions(-) diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index b0daf4779..19befe9f5 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -91,7 +91,7 @@ class PgAdmin(Flask): for key in list(module.__dict__.keys()): if isinstance(module.__dict__[key], PgAdminModule): yield module.__dict__[key] - except Exception as _: + except Exception: return [] @property @@ -372,7 +372,7 @@ def create_app(app_name=None): os.environ[ 'CORRUPTED_DB_BACKUP_FILE'] = backup_file_name app.logger.info('Database migration completed.') - except Exception as e: + except Exception: app.logger.error('Database migration failed') app.logger.error(traceback.format_exc()) raise RuntimeError('Migration failed') @@ -384,7 +384,7 @@ def create_app(app_name=None): try: db_upgrade(app) os.environ['CORRUPTED_DB_BACKUP_FILE'] = '' - except Exception as e: + except Exception: backup_db_file() # check all tables are present in the db. @@ -785,11 +785,10 @@ def create_app(app_name=None): ) abort(401) login_user(user) - elif config.SERVER_MODE and \ - not current_user.is_authenticated and \ - request.endpoint in ('redirects.index', 'security.login'): - if app.PGADMIN_EXTERNAL_AUTH_SOURCE in [KERBEROS, WEBSERVER]: - return authenticate.login() + elif config.SERVER_MODE and not current_user.is_authenticated and \ + request.endpoint in ('redirects.index', 'security.login') and \ + app.PGADMIN_EXTERNAL_AUTH_SOURCE in [KERBEROS, WEBSERVER]: + return authenticate.login() # if the server is restarted the in memory key will be lost # but the user session may still be active. Logout the user # to get the key again when login diff --git a/web/pgadmin/authenticate/webserver.py b/web/pgadmin/authenticate/webserver.py index 3d3e919c8..8178dfbc9 100644 --- a/web/pgadmin/authenticate/webserver.py +++ b/web/pgadmin/authenticate/webserver.py @@ -91,7 +91,7 @@ class WebserverAuthentication(BaseAuthentication): "Webserver authenticate failed.") session['pass_enc_key'] = ''.join( - (random.choice(string.ascii_lowercase) for x in range(10))) + (random.choice(string.ascii_lowercase) for _ in range(10))) useremail = request.environ.get('mail') if not useremail: useremail = '' diff --git a/web/pgadmin/browser/server_groups/servers/roles/__init__.py b/web/pgadmin/browser/server_groups/servers/roles/__init__.py index 89847d6d6..f0042098f 100644 --- a/web/pgadmin/browser/server_groups/servers/roles/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/roles/__init__.py @@ -1296,9 +1296,6 @@ WHERE ) status, res = conn.execute_scalar(SQL) - if not status: - return status, res - return status, res @check_precondition() @@ -1325,7 +1322,7 @@ WHERE for k, v in rargs.items(): try: data[k] = json.loads(v, encoding='utf-8') - except ValueError as ve: + except ValueError: data[k] = v required_args = ['role_op', 'did', 'old_role_name', diff --git a/web/pgadmin/browser/server_groups/servers/utils.py b/web/pgadmin/browser/server_groups/servers/utils.py index 6a2c96caf..2b318b444 100644 --- a/web/pgadmin/browser/server_groups/servers/utils.py +++ b/web/pgadmin/browser/server_groups/servers/utils.py @@ -266,7 +266,7 @@ def remove_saved_passwords(user_id): .filter(Server.user_id == user_id) \ .update({Server.password: None, Server.tunnel_password: None}) db.session.commit() - except Exception as _: + except Exception: db.session.rollback() raise diff --git a/web/pgadmin/feature_tests/pg_utilities_backup_restore_test.py b/web/pgadmin/feature_tests/pg_utilities_backup_restore_test.py index 75d67f09e..5810f68df 100644 --- a/web/pgadmin/feature_tests/pg_utilities_backup_restore_test.py +++ b/web/pgadmin/feature_tests/pg_utilities_backup_restore_test.py @@ -161,7 +161,7 @@ class PGUtilitiesBackupFeatureTest(BaseFeatureTest): test_gui_helper.close_process_watcher(self) test_gui_helper.close_bgprocess_popup(self) self.page.remove_server(self.server) - except Exception as e: + except Exception: print("PGUtilitiesBackupFeatureTest - " "Exception occurred in after method") finally: @@ -221,7 +221,6 @@ class PGUtilitiesBackupFeatureTest(BaseFeatureTest): click = False except Exception: retry -= 1 - pass def initiate_restore(self): tools_menu = self.driver.find_element( @@ -257,7 +256,6 @@ class PGUtilitiesBackupFeatureTest(BaseFeatureTest): click = False except Exception: retry -= 1 - pass def _check_escaped_characters(self, source_code, string_to_find, source): # For XSS we need to search against element's html code diff --git a/web/pgadmin/feature_tests/pg_utilities_maintenance_test.py b/web/pgadmin/feature_tests/pg_utilities_maintenance_test.py index 4a4b9a4ea..745e3cfee 100644 --- a/web/pgadmin/feature_tests/pg_utilities_maintenance_test.py +++ b/web/pgadmin/feature_tests/pg_utilities_maintenance_test.py @@ -170,7 +170,7 @@ class PGUtilitiesMaintenanceFeatureTest(BaseFeatureTest): test_utils.delete_table(self.server, self.database_name, self.table_name) self.page.remove_server(self.server) - except Exception as e: + except Exception: print("PGUtilitiesMaintenanceFeatureTest - " "Exception occurred in after method") finally: diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index dfab4e8fd..16da890d4 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -985,7 +985,7 @@ class Filemanager(object): try: # Check if the new file is inside the users directory pathlib.Path(new_name).relative_to(the_dir) - except ValueError as _: + except ValueError: return self.ERROR_NOT_ALLOWED with open(new_name, 'wb') as f: diff --git a/web/pgadmin/misc/themes/__init__.py b/web/pgadmin/misc/themes/__init__.py index 4f896cf82..c54762e7b 100644 --- a/web/pgadmin/misc/themes/__init__.py +++ b/web/pgadmin/misc/themes/__init__.py @@ -21,7 +21,7 @@ def get_all_themes(): try: all_themes.update(json.load(open(theme_file_path))) - except Exception as _: + except Exception: pass return all_themes diff --git a/web/pgadmin/static/js/SchemaView/index.jsx b/web/pgadmin/static/js/SchemaView/index.jsx index e86cccb6e..59a891c64 100644 --- a/web/pgadmin/static/js/SchemaView/index.jsx +++ b/web/pgadmin/static/js/SchemaView/index.jsx @@ -8,8 +8,7 @@ ////////////////////////////////////////////////////////////// import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react'; -import { Box, makeStyles } from '@material-ui/core'; -import {Accordion, AccordionSummary, AccordionDetails} from '@material-ui/core'; +import { Box, makeStyles, Accordion, AccordionSummary, AccordionDetails} from '@material-ui/core'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import SaveIcon from '@material-ui/icons/Save'; import PublishIcon from '@material-ui/icons/Publish'; @@ -323,14 +322,13 @@ const getDepChange = (currPath, newState, oldState, action)=>{ const getDeferredDepChange = (currPath, newState, oldState, action)=>{ if(action.deferredDepChange) { - let deferredPromiseList = action.deferredDepChange(currPath, newState, { + return action.deferredDepChange(currPath, newState, { type: action.type, path: action.path, value: action.value, depChange: action.depChange, oldState: _.cloneDeep(oldState), }); - return deferredPromiseList; } }; @@ -821,7 +819,6 @@ function SchemaPropertiesView({ }); }, [getInitData]); - let fullTabs = []; /* A simple loop to get all the controls for the fields */ schema.fields.forEach((field)=>{ @@ -831,10 +828,8 @@ function SchemaPropertiesView({ if(field.isFullTab) { tabsClassname[group] = classes.noPadding; - fullTabs.push(group); } - readonly = true; if(modeSupported) { group = groupLabels[group] || group || defaultTab; if(field.helpMessageMode && field.helpMessageMode.indexOf(viewHelperProps.mode) == -1) { diff --git a/web/pgadmin/tools/erd/tests/test_tables.py b/web/pgadmin/tools/erd/tests/test_tables.py index bfbe7b753..cea1d287d 100644 --- a/web/pgadmin/tools/erd/tests/test_tables.py +++ b/web/pgadmin/tools/erd/tests/test_tables.py @@ -52,7 +52,7 @@ class ERDTables(BaseTestGenerator): tables_utils.create_table(self.server, self.db_name, tab[0], tab[1]) connection.close() - except Exception as _: + except Exception: self.dropDB() raise diff --git a/web/pgadmin/tools/import_export_servers/__init__.py b/web/pgadmin/tools/import_export_servers/__init__.py index fec36c7ec..ed4774628 100644 --- a/web/pgadmin/tools/import_export_servers/__init__.py +++ b/web/pgadmin/tools/import_export_servers/__init__.py @@ -174,7 +174,7 @@ def load_servers(): for item in groups: all_servers.append(groups[item]) - except Exception as e: + except Exception: return internal_server_error( _('Unable to load the specified file.')) else: diff --git a/web/pgadmin/tools/psql/__init__.py b/web/pgadmin/tools/psql/__init__.py index e9c56adbf..c4cda7659 100644 --- a/web/pgadmin/tools/psql/__init__.py +++ b/web/pgadmin/tools/psql/__init__.py @@ -492,7 +492,7 @@ def socket_input(data): enter_key_press(data) else: other_key_press(data) - except Exception as e: + except Exception: # Delete socket id from sessions. # request.sid: refer request.sid as socket id. sio.emit('pty-output', diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index 3c70acce6..b7fb43d9b 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -765,7 +765,6 @@ define('tools.querytool', [ /* If sql editor is in a new tab, event fired is not available * instead, a poller is set up who will check */ - //var browser_qt_preferences = pgBrowser.get_preferences_for_module('browser'); var open_new_tab_qt = self.browser_preferences.new_browser_tab_open; if(open_new_tab_qt && open_new_tab_qt.includes('qt')) { pgBrowser.bind_beforeunload(); @@ -2010,7 +2009,7 @@ define('tools.querytool', [ method: 'DELETE', contentType: 'application/json', }) - .done(function() {}) + .done(function() { /* This is intentional */ }) .fail(function() { /* history clear fail should not affect query tool */ }); @@ -2437,7 +2436,7 @@ define('tools.querytool', [ }, }; }, - build:function() {}, + build:function() {/* */}, settings:{ message: null, }, @@ -2517,7 +2516,7 @@ define('tools.querytool', [ function() { self.initTransaction(); }, - function(error) { + function() { pgBrowser.Events.trigger( 'pgadmin:query_tool:connected_fail:' + self.transId, xhr, error ); @@ -3430,8 +3429,8 @@ define('tools.querytool', [ contentType: 'application/json', data: JSON.stringify(history_entry), }) - .done(function() {}) - .fail(function() {}); + .done(function() { /* This is intentional */ }) + .fail(function() { /* This is intentional */ }); self.gridView.history_collection.add(history_entry); }, @@ -5159,7 +5158,7 @@ define('tools.querytool', [ if(data.data_obj.db_id == db_did && !_.isEqual(db_name, data.data_obj.db_name)) { var message = `Current database has been moved or renamed to ${data.data_obj.db_name}. Click on the OK button to refresh the database name.`, - title = self.url_params.title; + title = ''; if(self.is_query_tool) {// for query tool diff --git a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py index dcbd76012..1e4c4a142 100644 --- a/web/pgadmin/tools/sqleditor/utils/save_changed_data.py +++ b/web/pgadmin/tools/sqleditor/utils/save_changed_data.py @@ -271,7 +271,7 @@ def save_changed_data(changed_data, columns_info, conn, command_obj, else: status, res = conn.execute_void( item['sql'], item['data']) - except Exception as _: + except Exception: failure_handle(res, item.get('row_id', 0)) raise diff --git a/web/pgadmin/utils/master_password.py b/web/pgadmin/utils/master_password.py index fcf15af53..27db924cf 100644 --- a/web/pgadmin/utils/master_password.py +++ b/web/pgadmin/utils/master_password.py @@ -57,7 +57,7 @@ def validate_master_password(password): return False else: return True - except Exception as _: + except Exception: False @@ -79,7 +79,7 @@ def set_masterpass_check_text(password, clear=False): .update({User.masterpass_check: masterpass_check}) db.session.commit() - except Exception as _: + except Exception: db.session.rollback() raise diff --git a/web/regression/feature_utils/pgadmin_page.py b/web/regression/feature_utils/pgadmin_page.py index 723583ab8..b514b3664 100644 --- a/web/regression/feature_utils/pgadmin_page.py +++ b/web/regression/feature_utils/pgadmin_page.py @@ -1272,7 +1272,7 @@ class PgadminPage: lambda d: d.find_element(By.XPATH, xpath)) f_scroll, r_scroll = 0, 0 return ele - except (TimeoutException, NoSuchElementException) as e: + except (TimeoutException, NoSuchElementException): tree_height = int((self.driver.find_element( By.XPATH, "//div[@class='file-tree']/div[1]/div/div"). value_of_css_property('height')).split("px")[0]) diff --git a/web/regression/python_test_utils/test_utils.py b/web/regression/python_test_utils/test_utils.py index a99700f58..2b6bf82fc 100644 --- a/web/regression/python_test_utils/test_utils.py +++ b/web/regression/python_test_utils/test_utils.py @@ -1796,7 +1796,7 @@ def module_patch(*args): patch.getter = lambda: imported patch.attribute = '.'.join(components[i:]) return patch - except Exception as exc: + except Exception: pass # did not find a module, just return the default mock