From 5e710f7ee30ad6a26f39349079b330b530aa07d1 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Mon, 8 Jan 2024 09:39:39 +0530 Subject: [PATCH] Fixed an issue where Schema Diff not generating difference for missing columns. #7104 --- docs/en_US/release_notes_8_2.rst | 1 + .../schemas/foreign_tables/__init__.py | 32 +++++++++---------- .../databases/schemas/tables/columns/utils.py | 4 +-- .../servers/databases/schemas/tables/utils.py | 21 ++++++------ 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/docs/en_US/release_notes_8_2.rst b/docs/en_US/release_notes_8_2.rst index 6d13f16e886..861b1c8cad8 100644 --- a/docs/en_US/release_notes_8_2.rst +++ b/docs/en_US/release_notes_8_2.rst @@ -46,3 +46,4 @@ Bug fixes | `Issue #7078 `_ - Fixed an issue where user is not able to cancel or terminate active queries from dashboard. | `Issue #7082 `_ - Fixed browser autocomplete related issues on pgAdmin authentication related pages. | `Issue #7091 `_ - Fixed an issue where auto commit/rollback setting not persisting across query tool connection change. + | `Issue #7104 `_ - Fixed an issue where Schema Diff not generating difference for missing columns. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py index 8482c1a19a7..384a5fdc39d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/__init__.py @@ -663,7 +663,7 @@ def get_tables(self, gid, sid, did, scid, foid=None): ) except Exception: - exc_type, exc_value, exc_traceback = sys.exc_info() + _, exc_value, _ = sys.exc_info() return internal_server_error(errormsg=str(exc_value)) @check_precondition @@ -702,7 +702,7 @@ def get_columns(self, gid, sid, did, scid, foid=None): status=200 ) except Exception: - exc_type, exc_value, exc_traceback = sys.exc_info() + _, exc_value, _ = sys.exc_info() return internal_server_error(errormsg=str(exc_value)) @check_precondition @@ -726,8 +726,8 @@ def create(self, gid, sid, did, scid): """ try: # Get SQL to create Foreign Table - SQL, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, - data=self.request) + SQL, _ = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, + data=self.request) # Most probably this is due to error if not isinstance(SQL, str): return SQL @@ -904,7 +904,7 @@ def sql(self, gid, sid, did, scid, foid=None, **kwargs): col_data = [] for c in data['columns']: - if ('inheritedfrom' not in c) or (c['inheritedfrom'] is None): + if c.get('inheritedfrom', None) is None: col_data.append(c) data['columns'] = col_data @@ -974,8 +974,8 @@ def msql(self, gid, sid, did, scid, foid=None): except TypeError: data[k] = v try: - SQL, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, - data=data, foid=foid) + SQL, _ = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, + data=data, foid=foid) # Most probably this is due to error if not isinstance(SQL, str): return SQL @@ -1189,8 +1189,7 @@ def _check_for_column_delete(self, columns, data, column_sql): c['schema'] = data['schema'] c['table'] = data['name'] # Sql for drop column - if 'inheritedfrom' not in c or \ - ('inheritedfrom' in c and c['inheritedfrom'] is None): + if c.get('inheritedfrom', None) is None: column_sql += render_template("/".join( [self.foreign_table_column_template_path, self._DELETE_SQL]), @@ -1233,8 +1232,8 @@ def _check_for_column_update(self, columns, data, column_sql, tid): old_col_data['cltype']) # Sql for alter column - if 'inheritedfrom' not in c and \ - 'inheritedfromtable' not in c: + if c.get('inheritedfrom', None) is None and \ + c.get('inheritedfromtable', None) is None: column_sql += render_template("/".join( [self.foreign_table_column_template_path, self._UPDATE_SQL]), @@ -1251,8 +1250,8 @@ def _check_for_column_add(self, columns, data, column_sql): c = column_utils.convert_length_precision_to_string(c) - if 'inheritedfrom' not in c and \ - 'inheritedfromtable' not in c: + if c.get('inheritedfrom', None) is None and \ + c.get('inheritedfromtable', None) is None: column_sql += render_template("/".join( [self.foreign_table_column_template_path, self._CREATE_SQL]), @@ -1416,7 +1415,7 @@ def _get_edit_types(self, cols): 'edit_mode_types_multi.sql']), type_ids=",".join(map(lambda x: str(x), edit_types.keys()))) - status, res = self.conn.execute_2darray(SQL) + _, res = self.conn.execute_2darray(SQL) for row in res['rows']: edit_types[row['main_oid']] = sorted(row['edit_types']) @@ -1759,9 +1758,8 @@ def get_sql_from_diff(self, **kwargs): target_schema = kwargs.get('target_schema', None) if data: - sql, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, - data=data, foid=oid, - is_schema_diff=True) + sql, _ = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, + data=data, foid=oid, is_schema_diff=True) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py index 64ce740ef1e..1038282cb1b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py @@ -336,7 +336,7 @@ def _parse_format_col_for_edit(data, columns, column_acl): if action in columns: final_columns = [] for c in columns[action]: - if 'inheritedfrom' not in c: + if c.get('inheritedfrom', None) is None: final_columns.append(c) _parse_column_actions(final_columns, column_acl) @@ -440,7 +440,7 @@ def fetch_length_precision(data): length = False precision = False if 'elemoid' in data: - length, precision, typeval = \ + length, precision, _ = \ DataTypeReader.get_length_precision(data['elemoid']) # Set length and precision to None diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py index 6d3fc84cf77..3f040ea60f9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py @@ -1102,7 +1102,7 @@ def reset_statistics(self, scid, tid): tid: Table ID """ # checking the table existence using the function of the same class - schema_name, table_name = self.get_schema_and_table_name(tid) + _, table_name = self.get_schema_and_table_name(tid) if table_name is None: return gone(gettext(self.not_found_error_msg())) @@ -1274,8 +1274,7 @@ def _check_for_column_delete(self, columns, data, column_sql): c['schema'] = data['schema'] c['table'] = data['name'] # Sql for drop column - if 'inheritedfrom' not in c or \ - ('inheritedfrom' in c and c['inheritedfrom'] is None): + if c.get('inheritedfrom', None) is None: column_sql += render_template("/".join( [self.column_template_path, self._DELETE_SQL]), data=c, conn=self.conn).strip('\n') + \ @@ -1317,8 +1316,8 @@ def _check_for_column_update(self, columns, data, column_sql, tid): old_col_data['cltype']) # Sql for alter column - if 'inheritedfrom' not in c and \ - 'inheritedfromtable' not in c: + if c.get('inheritedfrom', None) is None and \ + c.get('inheritedfromtable', None) is None: column_sql += render_template("/".join( [self.column_template_path, self._UPDATE_SQL]), data=c, o_data=old_col_data, conn=self.conn @@ -1334,8 +1333,8 @@ def _check_for_column_add(self, columns, data, column_sql): c = column_utils.convert_length_precision_to_string(c) - if 'inheritedfrom' not in c and \ - 'inheritedfromtable' not in c: + if c.get('inheritedfrom', None) is None and \ + c.get('inheritedfromtable', None) is None: column_sql += render_template("/".join( [self.column_template_path, self._CREATE_SQL]), data=c, conn=self.conn).strip('\n') + \ @@ -1539,7 +1538,7 @@ def get_sql(self, did, scid, tid, data, res, add_not_exists_clause=False, sql = self._check_for_constraints(index_constraint_sql, data, did, tid, sql) else: - error, errmsg = BaseTableView._check_for_create_sql(data) + error, _ = BaseTableView._check_for_create_sql(data) if error: return gettext('-- definition incomplete'), data['name'] @@ -1599,7 +1598,7 @@ def update(self, gid, sid, did, scid, tid, **kwargs): parent_id = kwargs.get('parent_id', None) # checking the table existence using the function of the same class - schema_name, table_name = self.get_schema_and_table_name(tid) + _, table_name = self.get_schema_and_table_name(tid) if table_name is None: return gone(gettext(self.not_found_error_msg())) @@ -2053,7 +2052,7 @@ def get_table_locks(self, did, data): sql = render_template( "/".join([self.table_template_path, 'locks.sql']), did=did ) - status, lock_table_result = self.conn.execute_dict(sql) + _, lock_table_result = self.conn.execute_dict(sql) for row in lock_table_result['rows']: if row['relation'].strip('\"') == data['name']: @@ -2062,7 +2061,7 @@ def get_table_locks(self, did, data): "/".join([self.table_template_path, 'get_application_name.sql']), pid=row['pid'] ) - status, res = self.conn.execute_dict(sql) + _, res = self.conn.execute_dict(sql) application_name = res['rows'][0]['application_name']