Skip to content

Commit

Permalink
Fixed an issue where Schema Diff not generating difference for missin…
Browse files Browse the repository at this point in the history
…g columns. pgadmin-org#7104
  • Loading branch information
akshay-joshi committed Jan 8, 2024
1 parent ec5ea7e commit 5e710f7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
1 change: 1 addition & 0 deletions docs/en_US/release_notes_8_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Bug fixes
| `Issue #7078 <https://github.com/pgadmin-org/pgadmin4/issues/7078>`_ - Fixed an issue where user is not able to cancel or terminate active queries from dashboard.
| `Issue #7082 <https://github.com/pgadmin-org/pgadmin4/issues/7082>`_ - Fixed browser autocomplete related issues on pgAdmin authentication related pages.
| `Issue #7091 <https://github.com/pgadmin-org/pgadmin4/issues/7091>`_ - Fixed an issue where auto commit/rollback setting not persisting across query tool connection change.
| `Issue #7104 <https://github.com/pgadmin-org/pgadmin4/issues/7104>`_ - Fixed an issue where Schema Diff not generating difference for missing columns.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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]),
Expand All @@ -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]),
Expand Down Expand Up @@ -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'])

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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') + \
Expand Down Expand Up @@ -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
Expand All @@ -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') + \
Expand Down Expand Up @@ -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']

Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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']:
Expand All @@ -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']

Expand Down

0 comments on commit 5e710f7

Please sign in to comment.