Skip to content
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

xmlpatch crashes when the attribute to be deleted doesn't exist #92

Open
dmuhamedagic opened this issue Jul 14, 2022 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@dmuhamedagic
Copy link

With delete-attribute such as this one:
[delete-attribute, /domain/devices/disk[2]/driver[1], cache]
xmlpatch throws the KeyError exception if the referenced attribute doesn't exist in the element:
Traceback (most recent call last):
File "/usr/bin/xmlpatch", line 11, in
load_entry_point('xmldiff==2.4', 'console_scripts', 'xmlpatch')()
File "/usr/lib/python3/dist-packages/xmldiff/main.py", line 171, in patch_command
result = patch_file(args.patchfile, args.xmlfile)
File "/usr/lib/python3/dist-packages/xmldiff/main.py", line 148, in patch_file
tree = patch_tree(actions, tree)
File "/usr/lib/python3/dist-packages/xmldiff/main.py", line 124, in patch_tree
return patcher.patch(actions, tree)
File "/usr/lib/python3/dist-packages/xmldiff/patch.py", line 15, in patch
self.handle_action(action, result)
File "/usr/lib/python3/dist-packages/xmldiff/patch.py", line 22, in handle_action
method(action, tree)
File "/usr/lib/python3/dist-packages/xmldiff/patch.py", line 55, in _handle_DeleteAttrib
del tree.xpath(action.node)[0].attrib[action.name]
File "src/lxml/etree.pyx", line 2421, in lxml.etree._Attrib.delitem
File "src/lxml/apihelpers.pxi", line 582, in lxml.etree._delAttribute
KeyError: 'cache'

@dmuhamedagic
Copy link
Author

Perhaps just to do:
try: ....
except KeyError: pass

@regebro
Copy link
Contributor

regebro commented Jul 14, 2022

Well, we definitely need a better error message there, but that is at least a warning, because that means your patching doesn't match your source file.

@regebro regebro added the enhancement New feature or request label Jan 11, 2023
@regebro
Copy link
Contributor

regebro commented Jan 4, 2024

(or if it does it's a bug)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants