Fixed an issue where schema diff is not working when providing the options to Foreign Data Wrapper, Foreign Server, and User Mapping. Fixes #5754

This commit is contained in:
Akshay Joshi 2020-08-24 12:11:09 +05:30
parent b53de0c31d
commit 52d0241a17
5 changed files with 30 additions and 8 deletions

View File

@ -14,8 +14,9 @@ New features
Housekeeping
************
| `Issue #5344 <https://redmine.postgresql.org/issues/5344>`_ - Improve code coverage and API test cases for Grant Wizard.
| `Issue #5344 <https://redmine.postgresql.org/issues/5344>`_ - Improve code coverage and API test cases for Grant Wizard.
Bug fixes
*********
| `Issue #5754 <https://redmine.postgresql.org/issues/5754>`_ - Fixed an issue where schema diff is not working when providing the options to Foreign Data Wrapper, Foreign Server, and User Mapping.

View File

@ -682,13 +682,16 @@ class ForeignDataWrapperView(PGChildNodeView, SchemaDiffObjectCompare):
"""
is_valid_added_options = is_valid_changed_options = False
if 'fdwoptions' in data and 'added' in data['fdwoptions']:
if 'fdwoptions' in data and data['fdwoptions'] is not None and\
'added' in data['fdwoptions']:
is_valid_added_options, data['fdwoptions']['added'] = \
validate_options(
data['fdwoptions']['added'],
'fdwoption',
'fdwvalue')
if 'fdwoptions' in data and 'changed' in data['fdwoptions']:
if 'fdwoptions' in data and data['fdwoptions'] is not None and\
'changed' in data['fdwoptions']:
is_valid_changed_options, data['fdwoptions']['changed'] = \
validate_options(
data['fdwoptions']['changed'],
@ -960,6 +963,10 @@ class ForeignDataWrapperView(PGChildNodeView, SchemaDiffObjectCompare):
for row in rset['rows']:
status, data = self._fetch_properties(row['oid'])
if status:
# For schema diff if fdwoptions is None then convert it to
# the empty list.
if 'fdwoptions' in data and data['fdwoptions'] is None:
data['fdwoptions'] = []
res[row['name']] = data
return res

View File

@ -641,14 +641,16 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
data[arg] = old_data[arg]
is_valid_added_options = is_valid_changed_options = False
if 'fsrvoptions' in data and 'added' in data['fsrvoptions']:
if 'fsrvoptions' in data and data['fsrvoptions'] is not None and\
'added' in data['fsrvoptions']:
is_valid_added_options, data['fsrvoptions']['added'] = \
validate_options(
data['fsrvoptions']['added'],
'fsrvoption',
'fsrvvalue')
if 'fsrvoptions' in data and 'changed' in data['fsrvoptions']:
if 'fsrvoptions' in data and data['fsrvoptions'] is not None and\
'changed' in data['fsrvoptions']:
is_valid_changed_options, data['fsrvoptions']['changed'] = \
validate_options(
data['fsrvoptions']['changed'],
@ -921,6 +923,10 @@ class ForeignServerView(PGChildNodeView, SchemaDiffObjectCompare):
for row in rset['rows']:
status, data = self._fetch_properties(row['oid'])
if status:
# For schema diff if fsrvoptions is None then convert it to
# the empty list.
if 'fsrvoptions' in data and data['fsrvoptions'] is None:
data['fsrvoptions'] = []
res[row['name']] = data
return res

View File

@ -696,13 +696,15 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
# Allow user to set the blank value in fdwvalue
# field in option model
is_valid_added_options = is_valid_changed_options = False
if 'umoptions' in data and 'added' in data['umoptions']:
if 'umoptions' in data and data['umoptions'] is not None and\
'added' in data['umoptions']:
is_valid_added_options, data['umoptions']['added'] =\
validate_options(
data['umoptions']['added'],
'umoption',
'umvalue')
if 'umoptions' in data and 'changed' in data['umoptions']:
if 'umoptions' in data and data['umoptions'] is not None and\
'changed' in data['umoptions']:
is_valid_changed_options, data['umoptions']['changed'] =\
validate_options(
data['umoptions']['changed'],
@ -873,6 +875,10 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
for row in rset['rows']:
status, data = self._fetch_properties(row['oid'])
if status:
# For schema diff if umoptions is None then convert it to
# the empty list.
if 'umoptions' in data and data['umoptions'] is None:
data['umoptions'] = []
res[row['name']] = data
return res

View File

@ -33,6 +33,7 @@ def _get_source_list(added, source_dict, node, source_params, view_object,
:param group_name: group name
:return: list of source dict.
"""
global count
source_only = []
for item in added:
source_object_id = None
@ -109,6 +110,7 @@ def _get_target_list(removed, target_dict, node, target_params, view_object,
:param group_name: group name.
:return: list of target dict.
"""
global count
target_only = []
for item in removed:
target_object_id = None
@ -207,6 +209,7 @@ def _get_identical_and_different_list(intersect_keys, source_dict, target_dict,
:param other_param:
:return: return list of identical and different dict.
"""
global count
identical = []
different = []
dict1 = kwargs['dict1']
@ -349,7 +352,6 @@ def compare_dictionaries(**kwargs):
# Keys that are available in source and missing in target.
added = dict1_keys - dict2_keys
global count
source_only = _get_source_list(added, source_dict, node, source_params,
view_object, node_label, group_name)