Closed vimleshmishra closed 2 years ago
test_get_version ()
test case of test_package_util.py
file.General GitHub PrePush Checks
to pass.
- For test cases to pass, you will have to update
test_get_version ()
test case oftest_package_util.py
file.- Also, you will have to update the PR with JIRA ID and Description for
General GitHub PrePush Checks
to pass.
Thanks for highlighting.
Problem:
Since python 2-3 transition, in DB2 plugin, generated.definition subclasses are no longer hashable. Since in one of the workflows in DB2, we add a Definition subclass (SnapshotDefinitionDataPaths) to a set to make sure we don’t record duplicates, we started getting this error,
Traceback (most recent call last): File "plugin/platform_server.py", line 66, in _run_helper response = internal_func(request) File "./_linked.py", line 300, in _internal_staged_pre_snapshot File "./plugin_runner.py", line 63, in linked_pre_snapshot File "./plugin_operations/staging.py", line 53, in pre_snapshot File "./plugin_libs/linked_source.py", line 2449, in staging_push_pre_snapshot_validation File "./plugin_libs/db2_operations.py", line 734, in get_data_paths File "./plugin_libs/db2_operations.py", line 865, in get_all_paths_from_db2dart TypeError: unhashable type: 'SnapshotDefinitionDataPaths'
The same codeflow works just fine in older plugin that used python2.
Solution:
We have not implemented hash method in our Model class while we have implemented equals as below
In Python 3
In Python 2
Due to this change in behavior, we will not be able to store the generated class in any hash-supported data structure like dictionary OR set and we will get unhashable type errors.
To solve this we have tried to override the hash() similar to equals() method.
Please note that we have changed the behavior of hash() with this diff where earlier the default hash() method was using id(x) and if two objects are equals as per equal() contract they might not have the same hashcode but with this diff, we are using the properties of the object and if two objects are equals as per equal() contract they will have the same hashcode.
Testing
Manually reproduced this issue and verified that fix is working.
git blackbox -s appdata_python_samples --extra-params="-p virt-sdk-repo=https://github.com/vimleshmishra/virtualization-sdk.git -p virt-sdk-branch=develop"
git blackbox -s appdata_basic -c APPDATA_PYTHON_DIRECT_CENTOS73 --extra-params="-p virt-sdk-repo=https://github.com/vimleshmishra/virtualization-sdk.git -p virt-sdk-branch=develop"
git blackbox -s appdata_basic -c APPDATA_PYTHON_STAGED_CENTOS73 --extra-params="-p virt-sdk-repo=https://github.com/vimleshmishra/virtualization-sdk.git -p virt-sdk-branch=develop"