From 505a3ac960400025e4fea6e725c570c2a62af8a6 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Fri, 24 Jul 2020 11:46:30 +0530 Subject: [PATCH] =?UTF-8?q?1)=20Fixed=20cognitive=20complexity=20issues=20?= =?UTF-8?q?reported=C2=A0by=20SonarQube.=202)=20Fixed=20code=20smell=20'Ad?= =?UTF-8?q?d=20a=20nested=20comment=20explaining=20why=20this=20method=20i?= =?UTF-8?q?s=20=20=20=20empty,=20or=20complete=20the=20implementation'.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/migrations/script.py.mako | 1 + web/migrations/versions/02b9dccdcfcb_.py | 2 + web/migrations/versions/09d53fca90c7_.py | 8 +- web/migrations/versions/35f29b1701bd_.py | 1 + web/migrations/versions/3c1e4b6eda55_.py | 1 + web/migrations/versions/493cd3e39c0c_.py | 1 + web/migrations/versions/50aad68f99c2_.py | 2 + web/migrations/versions/7c56ea250085_.py | 2 + web/migrations/versions/7fedf8531802_.py | 1 + web/migrations/versions/84700139beb0_.py | 1 + web/migrations/versions/a68b374fe373_.py | 2 + web/migrations/versions/a77a0932a568_.py | 1 + web/migrations/versions/aa86fb60b73d_.py | 1 + web/migrations/versions/aff1436e3c8c_.py | 1 + web/migrations/versions/b5b87fdfcb30_.py | 1 + web/migrations/versions/ca00ec32581b_.py | 1 + web/migrations/versions/d39482714a2e_.py | 2 + web/migrations/versions/d85a62333272_.py | 1 + web/migrations/versions/ec1cac3399c9_.py | 1 + web/migrations/versions/ece2e76bf60e_.py | 1 + web/migrations/versions/ef590e979b0d_.py | 1 + web/migrations/versions/f195f9a4923d_.py | 1 + .../exclusion_constraint/__init__.py | 86 +++--- .../servers/databases/schemas/utils.py | 16 +- .../misc/bgprocess/process_executor.py | 2 +- web/pgadmin/tools/debugger/__init__.py | 247 +++++++++--------- web/pgadmin/tools/grant_wizard/__init__.py | 6 +- web/pgadmin/utils/__init__.py | 1 + .../feature_utils/base_feature_test.py | 3 + .../sql_template_test_base.py | 3 + web/regression/runtests.py | 1 + 31 files changed, 221 insertions(+), 178 deletions(-) diff --git a/web/migrations/script.py.mako b/web/migrations/script.py.mako index c8b4c12d3..02d4a0fcc 100644 --- a/web/migrations/script.py.mako +++ b/web/migrations/script.py.mako @@ -30,4 +30,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. ${downgrades if downgrades else "pass"} diff --git a/web/migrations/versions/02b9dccdcfcb_.py b/web/migrations/versions/02b9dccdcfcb_.py index 185eb2156..5d53275a4 100644 --- a/web/migrations/versions/02b9dccdcfcb_.py +++ b/web/migrations/versions/02b9dccdcfcb_.py @@ -31,5 +31,7 @@ def upgrade(): 'ALTER TABLE server ADD COLUMN fgcolor TEXT(10)' ) + def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/09d53fca90c7_.py b/web/migrations/versions/09d53fca90c7_.py index 3a31262a5..bd329319a 100644 --- a/web/migrations/versions/09d53fca90c7_.py +++ b/web/migrations/versions/09d53fca90c7_.py @@ -229,9 +229,5 @@ def upgrade(): def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - print(u""" - Cannot downgrade from this version - Exiting...""") - sys.exit(1) - # ### end Alembic commands ### + # pgAdmin only upgrades, downgrade not implemented. + pass diff --git a/web/migrations/versions/35f29b1701bd_.py b/web/migrations/versions/35f29b1701bd_.py index 8797ef1db..1180e7d89 100644 --- a/web/migrations/versions/35f29b1701bd_.py +++ b/web/migrations/versions/35f29b1701bd_.py @@ -48,4 +48,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/3c1e4b6eda55_.py b/web/migrations/versions/3c1e4b6eda55_.py index cd9bf67a6..aa4018a77 100644 --- a/web/migrations/versions/3c1e4b6eda55_.py +++ b/web/migrations/versions/3c1e4b6eda55_.py @@ -23,4 +23,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/493cd3e39c0c_.py b/web/migrations/versions/493cd3e39c0c_.py index fa37750b7..371ec4fb6 100644 --- a/web/migrations/versions/493cd3e39c0c_.py +++ b/web/migrations/versions/493cd3e39c0c_.py @@ -25,4 +25,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/50aad68f99c2_.py b/web/migrations/versions/50aad68f99c2_.py index 4cda56bdb..cadd2e445 100644 --- a/web/migrations/versions/50aad68f99c2_.py +++ b/web/migrations/versions/50aad68f99c2_.py @@ -78,5 +78,7 @@ def upgrade(): 'ALTER TABLE server ADD COLUMN service TEXT' ) + def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/7c56ea250085_.py b/web/migrations/versions/7c56ea250085_.py index 24af34981..54a08588c 100644 --- a/web/migrations/versions/7c56ea250085_.py +++ b/web/migrations/versions/7c56ea250085_.py @@ -86,5 +86,7 @@ def upgrade(): # Remove old data db.engine.execute("DROP TABLE server_old") + def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/7fedf8531802_.py b/web/migrations/versions/7fedf8531802_.py index 89401686a..4d055c829 100644 --- a/web/migrations/versions/7fedf8531802_.py +++ b/web/migrations/versions/7fedf8531802_.py @@ -48,4 +48,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/84700139beb0_.py b/web/migrations/versions/84700139beb0_.py index 455fd3d9b..10f26a98e 100644 --- a/web/migrations/versions/84700139beb0_.py +++ b/web/migrations/versions/84700139beb0_.py @@ -29,4 +29,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/a68b374fe373_.py b/web/migrations/versions/a68b374fe373_.py index 5e94bb1e2..1db15d658 100644 --- a/web/migrations/versions/a68b374fe373_.py +++ b/web/migrations/versions/a68b374fe373_.py @@ -37,5 +37,7 @@ def upgrade(): 'ALTER TABLE server ADD COLUMN tunnel_identity_file TEXT' ) + def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/a77a0932a568_.py b/web/migrations/versions/a77a0932a568_.py index 76ad244bf..2702aa279 100644 --- a/web/migrations/versions/a77a0932a568_.py +++ b/web/migrations/versions/a77a0932a568_.py @@ -88,4 +88,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/aa86fb60b73d_.py b/web/migrations/versions/aa86fb60b73d_.py index 1581af4c5..0dad53299 100644 --- a/web/migrations/versions/aa86fb60b73d_.py +++ b/web/migrations/versions/aa86fb60b73d_.py @@ -29,4 +29,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/aff1436e3c8c_.py b/web/migrations/versions/aff1436e3c8c_.py index 7a7c3017d..7be0428a7 100644 --- a/web/migrations/versions/aff1436e3c8c_.py +++ b/web/migrations/versions/aff1436e3c8c_.py @@ -24,4 +24,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/b5b87fdfcb30_.py b/web/migrations/versions/b5b87fdfcb30_.py index 124606fc9..076a80bb1 100644 --- a/web/migrations/versions/b5b87fdfcb30_.py +++ b/web/migrations/versions/b5b87fdfcb30_.py @@ -30,4 +30,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/ca00ec32581b_.py b/web/migrations/versions/ca00ec32581b_.py index cd6bf6877..635539002 100644 --- a/web/migrations/versions/ca00ec32581b_.py +++ b/web/migrations/versions/ca00ec32581b_.py @@ -31,4 +31,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/d39482714a2e_.py b/web/migrations/versions/d39482714a2e_.py index 66a51db87..039ca5332 100644 --- a/web/migrations/versions/d39482714a2e_.py +++ b/web/migrations/versions/d39482714a2e_.py @@ -43,5 +43,7 @@ def upgrade(): """ ) + def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/d85a62333272_.py b/web/migrations/versions/d85a62333272_.py index 0b16faf93..856362081 100644 --- a/web/migrations/versions/d85a62333272_.py +++ b/web/migrations/versions/d85a62333272_.py @@ -23,4 +23,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/ec1cac3399c9_.py b/web/migrations/versions/ec1cac3399c9_.py index e6739dfcb..d8e0349b5 100644 --- a/web/migrations/versions/ec1cac3399c9_.py +++ b/web/migrations/versions/ec1cac3399c9_.py @@ -39,4 +39,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/ece2e76bf60e_.py b/web/migrations/versions/ece2e76bf60e_.py index 2142f65f8..6ab954076 100644 --- a/web/migrations/versions/ece2e76bf60e_.py +++ b/web/migrations/versions/ece2e76bf60e_.py @@ -31,4 +31,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/ef590e979b0d_.py b/web/migrations/versions/ef590e979b0d_.py index be219c511..2c9d422d8 100644 --- a/web/migrations/versions/ef590e979b0d_.py +++ b/web/migrations/versions/ef590e979b0d_.py @@ -43,4 +43,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/migrations/versions/f195f9a4923d_.py b/web/migrations/versions/f195f9a4923d_.py index 2402565bc..0c8132d9b 100644 --- a/web/migrations/versions/f195f9a4923d_.py +++ b/web/migrations/versions/f195f9a4923d_.py @@ -45,4 +45,5 @@ def upgrade(): def downgrade(): + # pgAdmin only upgrades, downgrade not implemented. pass diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py index 0a06ce473..994a9fea5 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/__init__.py @@ -462,6 +462,41 @@ class ExclusionConstraintView(PGChildNodeView): )) return res + @staticmethod + def parse_input_data(data): + """ + This function is used to parse the input data. + :param data: + :return: + """ + for k, v in data.items(): + try: + # comments should be taken as is because if user enters a + # json comment it is parsed by loads which should not happen + if k in ('comment',): + data[k] = v + else: + data[k] = json.loads(v, encoding='utf-8') + except (ValueError, TypeError, KeyError): + data[k] = v + + return data + + @staticmethod + def check_required_args(data, required_args): + """ + This function is used to check the required arguments. + :param data: + :param required_args: + :return: + """ + for arg in required_args: + if arg not in data or \ + (isinstance(data[arg], list) and len(data[arg]) < 1): + return arg + + return None + @check_precondition def create(self, gid, sid, did, scid, tid, exid=None): """ @@ -480,36 +515,22 @@ class ExclusionConstraintView(PGChildNodeView): """ required_args = ['columns'] - data = request.form if request.form else json.loads( - request.data, encoding='utf-8' - ) - - for k, v in data.items(): - try: - # comments should be taken as is because if user enters a - # json comment it is parsed by loads which should not happen - if k in ('comment',): - data[k] = v - else: - data[k] = json.loads(v, encoding='utf-8') - except (ValueError, TypeError, KeyError): - data[k] = v - - for arg in required_args: - if arg not in data or \ - (isinstance(data[arg], list) and len(data[arg]) < 1): - return make_json_response( - status=400, - success=0, - errormsg=_( - "Could not find required parameter ({})." - ).format(arg) - ) + data = json.loads(request.data, encoding='utf-8') + data = self.parse_input_data(data) + arg_missing = self.check_required_args(data, required_args) + if arg_missing is not None: + return make_json_response( + status=400, + success=0, + errormsg=_( + "Could not find required parameter ({})." + ).format(arg_missing) + ) data['schema'] = self.schema data['table'] = self.table try: - if 'name' not in data or data['name'] == "": + if data.get('name', '') == "": SQL = render_template( "/".join([self.template_path, 'begin.sql'])) # Start transaction. @@ -528,7 +549,7 @@ class ExclusionConstraintView(PGChildNodeView): self.end_transaction() return internal_server_error(errormsg=res) - if 'name' not in data or data['name'] == "": + if data.get('name', '') == "": sql = render_template( "/".join([self.template_path, 'get_oid_with_transaction.sql']), @@ -784,13 +805,8 @@ class ExclusionConstraintView(PGChildNodeView): columns = [] for row in res['rows']: - if row['options'] & 1: - order = False - nulls_order = True if (row['options'] & 2) else False - else: - order = True - nulls_order = True if (row['options'] & 2) else False - + nulls_order = True if (row['options'] & 2) else False + order = False if row['options'] & 1 else True columns.append({"column": row['coldef'].strip('"'), "oper_class": row['opcname'], "order": order, @@ -814,7 +830,7 @@ class ExclusionConstraintView(PGChildNodeView): data['include'] = [col['colname'] for col in res['rows']] - if not data['amname'] or data['amname'] == '': + if data.get('amname', '') == "": data['amname'] = 'btree' SQL = render_template( diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py index 3fd55868d..8e54d85e8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py @@ -501,9 +501,6 @@ class VacuumSettings: """ vacuum_settings = dict() - def __init__(self): - pass - def fetch_default_vacuum_settings(self, conn, sid, setting_type): """ This function is used to fetch and cached the default vacuum settings @@ -583,16 +580,11 @@ class VacuumSettings: row_name = row['name'] if type == 'toast': row_name = 'toast_{0}'.format(row['name']) - if row_name in result and result[row_name] is not None: - if row['column_type'] == 'number': - value = float(result[row_name]) - value = int(value) if value % 1 == 0 else value - else: - value = int(result[row_name]) - row['value'] = value + if result.get(row_name, None) is not None: + value = float(result[row_name]) + row['value'] = int(value) if value % 1 == 0 else value else: - if 'value' in row: - row.pop('value') + row.pop('value', None) return vacuum_settings_tmp diff --git a/web/pgadmin/misc/bgprocess/process_executor.py b/web/pgadmin/misc/bgprocess/process_executor.py index 1569c97d9..074554933 100755 --- a/web/pgadmin/misc/bgprocess/process_executor.py +++ b/web/pgadmin/misc/bgprocess/process_executor.py @@ -371,8 +371,8 @@ def execute(argv): _log('Bye!') -# Let's ignore all the signal comming to us. def signal_handler(signal, msg): + # Let's ignore all the signal comming to us. pass diff --git a/web/pgadmin/tools/debugger/__init__.py b/web/pgadmin/tools/debugger/__init__.py index d3f458466..27583bf2a 100644 --- a/web/pgadmin/tools/debugger/__init__.py +++ b/web/pgadmin/tools/debugger/__init__.py @@ -607,6 +607,87 @@ def direct_new(trans_id): ) +def get_debugger_version(conn): + """ + Function returns the debugger version. + :param conn: + :return: + """ + debugger_version = 0 + status, rid = conn.execute_scalar( + "SELECT COUNT(*) FROM pg_catalog.pg_proc p" + " LEFT JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid" + " WHERE n.nspname = ANY(current_schemas(false)) AND" + " p.proname = 'pldbg_get_proxy_info';" + ) + + if not status: + return False, internal_server_error(errormsg=rid) + + if rid == 0: + debugger_version = 1 + + status, rid = conn.execute_scalar( + "SELECT proxyapiver FROM pldbg_get_proxy_info();") + + if status and rid in (2, 3): + debugger_version = rid + + return True, debugger_version + + +def validate_debug(conn, debug_type, is_superuser): + """ + This function is used to validate the options required for debugger. + :param conn: + :param debug_type: + :param is_superuser: + :return: + """ + if debug_type == 'indirect' and not is_superuser: + # If user is super user then we should check debugger library is + # loaded or not + msg = gettext("You must be a superuser to set a global breakpoint" + " and perform indirect debugging.") + return False, internal_server_error(errormsg=msg) + + status, rid_pre = conn.execute_scalar( + "SHOW shared_preload_libraries" + ) + if not status: + return False, internal_server_error( + gettext("Could not fetch debugger plugin information.") + ) + + # Need to check if plugin is really loaded or not with + # "plugin_debugger" string + if debug_type == 'indirect' and "plugin_debugger" not in rid_pre: + msg = gettext( + "The debugger plugin is not enabled. " + "Please add the plugin to the shared_preload_libraries " + "setting in the postgresql.conf file and restart the " + "database server for indirect debugging." + ) + current_app.logger.debug(msg) + return False, internal_server_error(msg) + + # Check debugger extension version for EPAS 11 and above. + # If it is 1.0 then return error to upgrade the extension. + status, ext_version = conn.execute_scalar( + "SELECT installed_version FROM pg_catalog.pg_available_extensions " + "WHERE name = 'pldbgapi'" + ) + if not status: + return False, internal_server_error(errormsg=ext_version) + if conn.manager.server_type == 'ppas' and conn.manager.sversion >= 110000 \ + and float(ext_version) < 1.1: + return False, internal_server_error( + errormsg=gettext("Please upgrade the pldbgapi extension " + "to 1.1 or above and try again.")) + + return True, None + + @blueprint.route( '/initialize_target/////' '/', @@ -644,11 +725,8 @@ def initialize_target(debug_type, trans_id, sid, did, # Create asynchronous connection using random connection id. conn_id = str(random.randint(1, 9999999)) - try: - manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid) - conn = manager.connection(did=did, conn_id=conn_id) - except Exception as e: - return internal_server_error(errormsg=str(e)) + manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid) + conn = manager.connection(did=did, conn_id=conn_id) # Connect the Server status, msg = conn.connect() @@ -656,49 +734,9 @@ def initialize_target(debug_type, trans_id, sid, did, return internal_server_error(errormsg=str(msg)) user = manager.user_info - if debug_type == 'indirect': - # If user is super user then we should check debugger library is - # loaded or not - if not user['is_superuser']: - msg = gettext("You must be a superuser to set a global breakpoint" - " and perform indirect debugging.") - return internal_server_error(errormsg=msg) - else: - status_in, rid_pre = conn.execute_scalar( - "SHOW shared_preload_libraries" - ) - if not status_in: - return internal_server_error( - gettext("Could not fetch debugger plugin information.") - ) - - # Need to check if plugin is really loaded or not with - # "plugin_debugger" string - if "plugin_debugger" not in rid_pre: - msg = gettext( - "The debugger plugin is not enabled. " - "Please add the plugin to the shared_preload_libraries " - "setting in the postgresql.conf file and restart the " - "database server for indirect debugging." - ) - current_app.logger.debug(msg) - return internal_server_error(msg) - - # Check debugger extension version for EPAS 11 and above. - # If it is 1.0 then return error to upgrade the extension. - if manager.server_type == 'ppas' and manager.sversion >= 110000: - status, ext_version = conn.execute_scalar( - "SELECT installed_version FROM pg_catalog.pg_available_extensions " - "WHERE name = 'pldbgapi'" - ) - - if not status: - return internal_server_error(errormsg=ext_version) - else: - if float(ext_version) < 1.1: - return internal_server_error( - errormsg=gettext("Please upgrade the pldbgapi extension " - "to 1.1 or above and try again.")) + status, error = validate_debug(conn, debug_type, user['is_superuser']) + if not status: + return error # Set the template path required to read the sql files template_path = 'debugger/sql' @@ -718,30 +756,10 @@ def initialize_target(debug_type, trans_id, sid, did, func_id = tr_set['rows'][0]['tgfoid'] - status = True - # Find out the debugger version and store it in session variables - status, rid = conn.execute_scalar( - "SELECT COUNT(*) FROM pg_catalog.pg_proc p" - " LEFT JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid" - " WHERE n.nspname = ANY(current_schemas(false)) AND" - " p.proname = 'pldbg_get_proxy_info';" - ) - + status, debugger_version = get_debugger_version(conn) if not status: - return internal_server_error(errormsg=rid) - else: - if rid == 0: - debugger_version = 1 - - status, rid = conn.execute_scalar( - "SELECT proxyapiver FROM pldbg_get_proxy_info();") - - if status: - if rid == 2 or rid == 3: - debugger_version = rid - else: - status = False + return debugger_version # Add the debugger version information to pgadmin4 log file current_app.logger.debug("Debugger version is: %d", debugger_version) @@ -753,9 +771,8 @@ def initialize_target(debug_type, trans_id, sid, did, # provide the data from another session so below condition will # be be required if request.method == 'POST': - data = json.loads(request.values['data'], encoding='utf-8') - if data: - de_inst.function_data['args_value'] = data + de_inst.function_data['args_value'] = \ + json.loads(request.values['data'], encoding='utf-8') # Update the debugger data session variable # Here frame_id is required when user debug the multilevel function. @@ -1143,52 +1160,44 @@ def execute_debugger_query(trans_id, query_type): conn_id=de_inst.debugger_data['exe_conn_id']) # find the debugger version and execute the query accordingly - dbg_version = de_inst.debugger_data['debugger_version'] - if dbg_version <= 2: - template_path = 'debugger/sql/v1' - else: - template_path = 'debugger/sql/v2' + template_path = 'debugger/sql/v1' \ + if de_inst.debugger_data['debugger_version'] <= 2 \ + else 'debugger/sql/v2' - if conn.connected(): - sql = render_template( - "/".join([template_path, query_type + ".sql"]), - session_id=de_inst.debugger_data['session_id'] - ) - # As the query type is continue or step_into or step_over then we - # may get result after some time so poll the result. - # We need to update the frame id variable when user move the next - # step for debugging. - if query_type == 'continue' or query_type == 'step_into' or \ - query_type == 'step_over': - # We should set the frame_id to 0 when execution starts. - if de_inst.debugger_data['frame_id'] != 0: - de_inst.debugger_data['frame_id'] = 0 - de_inst.update_session() - - status, result = conn.execute_async(sql) - if not status: - internal_server_error(errormsg=result) - return make_json_response( - data={'status': status, 'result': result} - ) - elif query_type == 'abort_target': - status, result = conn.execute_dict(sql) - if not status: - return internal_server_error(errormsg=result) - else: - return make_json_response( - info=gettext('Debugging aborted successfully.'), - data={'status': 'Success', 'result': result} - ) - else: - status, result = conn.execute_dict(sql) - if not status: - return internal_server_error(errormsg=result) - else: + if not conn.connected(): result = gettext('Not connected to server or connection ' 'with the server has been closed.') return internal_server_error(errormsg=result) + sql = render_template( + "/".join([template_path, query_type + ".sql"]), + session_id=de_inst.debugger_data['session_id'] + ) + # As the query type is continue or step_into or step_over then we + # may get result after some time so poll the result. + # We need to update the frame id variable when user move the next + # step for debugging. + if query_type in ('continue', 'step_into', 'step_over'): + # We should set the frame_id to 0 when execution starts. + de_inst.debugger_data['frame_id'] = 0 + de_inst.update_session() + + status, result = conn.execute_async(sql) + if not status: + return internal_server_error(errormsg=result) + return make_json_response( + data={'status': status, 'result': result} + ) + + status, result = conn.execute_dict(sql) + if not status: + return internal_server_error(errormsg=result) + if query_type == 'abort_target': + return make_json_response( + info=gettext('Debugging aborted successfully.'), + data={'status': 'Success', 'result': result} + ) + return make_json_response( data={'status': 'Success', 'result': result['rows']} ) @@ -1230,7 +1239,8 @@ def messages(trans_id): port_number = '' if conn.connected(): - status, result = conn.poll() + status = 'Busy' + _, result = conn.poll() notify = conn.messages() if notify: # In notice message we need to find "PLDBGBREAK" string to find @@ -1240,19 +1250,12 @@ def messages(trans_id): # From the above message we need to find out port number # as "7" so below logic will find 7 as port number # and attach listened to that port number - port_found = False tmp_list = list(filter(lambda x: 'PLDBGBREAK' in x, notify)) if len(tmp_list) > 0: port_number = re.search(r'\d+', tmp_list[0]) if port_number is not None: status = 'Success' port_number = port_number.group(0) - port_found = True - - if not port_found: - status = 'Busy' - else: - status = 'Busy' return make_json_response( data={'status': status, 'result': port_number} diff --git a/web/pgadmin/tools/grant_wizard/__init__.py b/web/pgadmin/tools/grant_wizard/__init__.py index 9d387287b..79c5529c4 100644 --- a/web/pgadmin/tools/grant_wizard/__init__.py +++ b/web/pgadmin/tools/grant_wizard/__init__.py @@ -19,7 +19,7 @@ from urllib.parse import unquote from pgadmin.browser.server_groups.servers.utils import parse_priv_to_db from pgadmin.utils import PgAdminModule from pgadmin.utils.ajax import make_response as ajax_response, \ - make_json_response, internal_server_error + make_json_response, internal_server_error, bad_request from pgadmin.utils.driver import get_driver from config import PG_DEFAULT_DRIVER @@ -144,7 +144,9 @@ def check_precondition(f): @blueprint.route("/") @login_required def index(): - pass + return bad_request( + errormsg=gettext("This URL cannot be called directly.") + ) @blueprint.route("/grant_wizard.js") diff --git a/web/pgadmin/utils/__init__.py b/web/pgadmin/utils/__init__.py index 6e470a943..2da8bd0f1 100644 --- a/web/pgadmin/utils/__init__.py +++ b/web/pgadmin/utils/__init__.py @@ -52,6 +52,7 @@ class PgAdminModule(Blueprint): self.before_app_first_request(create_module_preference) def register_preferences(self): + # To be implemented by child classes pass def register(self, app, options, first_registration=False): diff --git a/web/regression/feature_utils/base_feature_test.py b/web/regression/feature_utils/base_feature_test.py index 4c41474c1..ac5e78e73 100644 --- a/web/regression/feature_utils/base_feature_test.py +++ b/web/regression/feature_utils/base_feature_test.py @@ -48,12 +48,15 @@ class BaseFeatureTest(BaseTestGenerator): raise def runTest(self): + # To be implemented by child classes pass def before(self): + # To be implemented by child classes pass def after(self): + # To be implemented by child classes pass def tearDown(self): diff --git a/web/regression/python_test_utils/sql_template_test_base.py b/web/regression/python_test_utils/sql_template_test_base.py index ec169d853..91ff5d135 100644 --- a/web/regression/python_test_utils/sql_template_test_base.py +++ b/web/regression/python_test_utils/sql_template_test_base.py @@ -28,12 +28,15 @@ class SQLTemplateTestBase(BaseTestGenerator): self.database_name = -1 def test_setup(self, connection, cursor): + # To be implemented by child classes pass def generate_sql(self, version): + # To be implemented by child classes pass def assertions(self, fetch_result, descriptions): + # To be implemented by child classes pass def runTest(self): diff --git a/web/regression/runtests.py b/web/regression/runtests.py index bcb7b2a62..067cdcae8 100644 --- a/web/regression/runtests.py +++ b/web/regression/runtests.py @@ -410,6 +410,7 @@ class StreamToLogger(object): self.logger.log(self.log_level, line.rstrip()) def flush(self): + # Function required to be implemented for logger pass