From 52d0241a1795f57f3702e293d46a2f6c19b4bc8b Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Mon, 24 Aug 2020 12:11:09 +0530 Subject: [PATCH] Fixed an issue where schema diff is not working when providing the options to Foreign Data Wrapper, Foreign Server, and User Mapping. Fixes #5754 --- docs/en_US/release_notes_4_26.rst | 3 ++- .../databases/foreign_data_wrappers/__init__.py | 11 +++++++++-- .../foreign_data_wrappers/foreign_servers/__init__.py | 10 ++++++++-- .../foreign_servers/user_mappings/__init__.py | 10 ++++++++-- web/pgadmin/tools/schema_diff/directory_compare.py | 4 +++- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/en_US/release_notes_4_26.rst b/docs/en_US/release_notes_4_26.rst index 04fb8ce3a..0ebea240a 100644 --- a/docs/en_US/release_notes_4_26.rst +++ b/docs/en_US/release_notes_4_26.rst @@ -14,8 +14,9 @@ New features Housekeeping ************ -| `Issue #5344 `_ - Improve code coverage and API test cases for Grant Wizard. +| `Issue #5344 `_ - Improve code coverage and API test cases for Grant Wizard. Bug fixes ********* +| `Issue #5754 `_ - Fixed an issue where schema diff is not working when providing the options to Foreign Data Wrapper, Foreign Server, and User Mapping. diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py index 9c10e10e4..64ae9974c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/__init__.py @@ -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 diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py index ccf3c5222..1aef6aca8 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/__init__.py @@ -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 diff --git a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py index 8a59e69ef..ee7b85b9d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/user_mappings/__init__.py @@ -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 diff --git a/web/pgadmin/tools/schema_diff/directory_compare.py b/web/pgadmin/tools/schema_diff/directory_compare.py index 1693ec7a9..ee143c319 100644 --- a/web/pgadmin/tools/schema_diff/directory_compare.py +++ b/web/pgadmin/tools/schema_diff/directory_compare.py @@ -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)