-
Notifications
You must be signed in to change notification settings - Fork 92
Fixed to retain static items when reloading(#57404) #1812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1002,7 +1002,31 @@ def test_update_attribute_options(self, app): | |
| expected_dict = {"isHide": False, "isShowList": False, "isNonDisplay": False, "isSpecifyNewline": False, "required": False,"key": "key", "type": "fieldset", "items": [{"key": "key.subitem_select_item", "type": "select", "title": "値", "titleMap": [{"name": "a", "value": "a"}, {"name": "b", "value": "b"}], "title_i18n": {"en": "Test Value", "ja": "テスト値"}, "title_i18n_temp": {"en": "Test Value", "ja": "テスト値"},'isHide': False,'isNonDisplay': False,'isShowList': False, 'isSpecifyNewline': False,'required': False}], "title": "abcdef", "title_i18n": {"en": "", "ja": ""}} | ||
| ItemTypes.update_attribute_options(old_value,new_value,"ALL") | ||
| TestCase().assertDictEqual(new_value, expected_dict) | ||
|
|
||
| def test_update_mapping_without_static(self): | ||
| old_data={ | ||
| "str_not_static":"b", | ||
| "str_static":"=str_static_value", | ||
| "dict_not_static":{"a":"b"}, | ||
| "dict_static":{"not_static":"a","static":"=dict_static_value"}, | ||
| "not_exist_path":{"not_static":"a","static":"=not_exist_static_value"}, | ||
| } | ||
|
|
||
| new_data={ | ||
| "str_not_static":"b", | ||
| "str_static":"c", | ||
| "dict_not_static":{"a":"b"}, | ||
| "dict_static":{"not_static":"a","static":"b"}, | ||
| } | ||
|
|
||
| test = { | ||
| "str_not_static":"b", | ||
| "str_static":"=str_static_value", | ||
| "dict_not_static":{"a":"b"}, | ||
| "dict_static":{"not_static":"a","static":"=dict_static_value"} | ||
| } | ||
|
|
||
| result = ItemTypes.update_mapping_without_static(old_data,new_data) | ||
| assert result==test | ||
|
Comment on lines
+1005
to
+1029
|
||
|
|
||
| # class ItemTypeEditHistory(RecordBase): | ||
| # .tox/c1/bin/pytest --cov=weko_records tests/test_api.py::test_item_type_edit_history -v -s -vv --cov-branch --cov-report=term --cov-config=tox.ini --basetemp=/code/modules/weko-records/.tox/c1/tmp | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1013,7 +1013,7 @@ def reload(cls, itemtype_id, mapping_dict, specified_list=[], renew_value='None' | |||||||||||||||||||||||||||||
| return result | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| data = pickle.loads(pickle.dumps(item_type.render, -1)) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| item_type_mapping = Mapping.get_record(itemtype_id) | ||||||||||||||||||||||||||||||
| pat1 = re.compile(r'cus_(\d+)') | ||||||||||||||||||||||||||||||
| for idx, i in enumerate(data['table_row_map']['form']): | ||||||||||||||||||||||||||||||
| if isinstance(i,dict) and 'key' in i: | ||||||||||||||||||||||||||||||
|
|
@@ -1029,7 +1029,9 @@ def reload(cls, itemtype_id, mapping_dict, specified_list=[], renew_value='None' | |||||||||||||||||||||||||||||
| if _prop: | ||||||||||||||||||||||||||||||
| # fix mapping | ||||||||||||||||||||||||||||||
| if _property_id in mapping_dict: | ||||||||||||||||||||||||||||||
| data['table_row_map']['mapping'][_prop_id] = mapping_dict.get(_property_id) | ||||||||||||||||||||||||||||||
| update_mapping = cls.update_mapping_without_static(item_type_mapping.get(_prop_id,{}),mapping_dict.get(_property_id)) \ | ||||||||||||||||||||||||||||||
| if item_type_mapping else mapping_dict.get(_property_id) | ||||||||||||||||||||||||||||||
|
Comment on lines
+1032
to
+1033
|
||||||||||||||||||||||||||||||
| update_mapping = cls.update_mapping_without_static(item_type_mapping.get(_prop_id,{}),mapping_dict.get(_property_id)) \ | |
| if item_type_mapping else mapping_dict.get(_property_id) | |
| update_mapping = ( | |
| cls.update_mapping_without_static( | |
| item_type_mapping.get(_prop_id, {}), | |
| mapping_dict.get(_property_id), | |
| ) | |
| if item_type_mapping | |
| else mapping_dict.get(_property_id) | |
| ) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace after result = []. Remove the trailing space for cleaner code.
| result = [] | |
| result = [] |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space around comparison operators. For consistency with PEP 8 and the rest of the codebase, add spaces: if path != "" else key
| result+=find_static_value(value,f"{path}.{key}" if path!="" else key) | |
| result+=find_static_value(value,f"{path}.{key}" if path != "" else key) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space around augmented assignment operator. For consistency with PEP 8, add spaces: result += find_static_value(...)
| if isinstance(d,dict): | |
| for key, value in d.items(): | |
| result+=find_static_value(value,f"{path}.{key}" if path!="" else key) | |
| elif isinstance(d,str): | |
| if d.startswith("="): | |
| result.append((path,d)) | |
| if isinstance(d, dict): | |
| for key, value in d.items(): | |
| result += find_static_value(value, f"{path}.{key}" if path != "" else key) | |
| elif isinstance(d, str): | |
| if d.startswith("="): | |
| result.append((path, d)) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space around comparison operators in tuple unpacking. For consistency with PEP 8, format as: result.append((path, d))
| result.append((path,d)) | |
| result.append((path, d)) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code doesn't check if temp[key] is a dictionary before attempting to access it in the next iteration. If an intermediate value in the path is not a dictionary (e.g., it's a string or list), this will raise a TypeError when trying to use it as a dictionary in the next iteration. Consider adding a type check: if key not in temp or not isinstance(temp[key], dict):
| if key not in temp: | |
| is_exist_field = False | |
| break | |
| temp = temp[key] | |
| if is_exist_field: | |
| # Ensure the current container is a dict and contains the key, | |
| # and that the next value is also a dict (since it will be traversed). | |
| if not isinstance(temp, dict) or key not in temp or not isinstance(temp[key], dict): | |
| is_exist_field = False | |
| break | |
| temp = temp[key] | |
| if is_exist_field and isinstance(temp, dict): |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docstring, "Only existing paths in mapping_prop will be updated; missing paths are ignored." However, the code doesn't check if the final key exists before updating it. If keys[-1] doesn't exist in temp, the code will still create it. Consider adding: if is_exist_field and keys[-1] in temp: to align with the documented behavior.
| if is_exist_field: | |
| if is_exist_field and keys[-1] in temp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test doesn't verify the edge case where an intermediate path exists but is not a dictionary (e.g.,
{'a': 'string_value'}when trying to accessa.b). This could lead to a TypeError at runtime. Consider adding a test case to ensure the method handles this scenario gracefully.