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

Calls to convert_* have misaligned arguments #89

Closed
mmabey opened this issue Oct 19, 2021 · 3 comments
Closed

Calls to convert_* have misaligned arguments #89

mmabey opened this issue Oct 19, 2021 · 3 comments

Comments

@mmabey
Copy link

mmabey commented Oct 19, 2021

Describe the bug
In the convert() function in dicttoxml.py, there are several calls to convert_* functions that use positional arguments that are getting sent to the wrong parameters.

For example,

return convert_kv(item_name, obj, attr_type, cdata)

makes a call to convert_kv(), but the signature of that function has the cdata parameter after the attr parameter, so the two get mixed up on the call:
def convert_kv(key, val, attr_type, attr={}, cdata: bool = False):

I think if these calls were switched to use keyword parameters, this bug would be fixed very quickly. Presently, though, it's causing things to fail for me.

To Reproduce
Running the following in a Python console shows the error I'm seeing:

from json import dumps
from json2xml.json2xml import Json2xml
input_dict = {'response': {'results': {'user': [{'name': 'Ezequiel', 'age': '33', 'city': 'San Isidro'}, {'name': 'Belén', 'age': '30', 'city': 'San Isidro'}]}}}
Json2xml(dumps(input_dict), wrapper='response', pretty=False, attr_type=False, item_wrap=False).to_xml()

The resulting AttributeError: 'bool' object has no attribute 'items' error is a result of attr being set to False instead of its default value of an empty dict {}.

@vinitkumar
Copy link
Owner

@mmabey Thanks for reporting this issue. I am a bit swamped at work these days. Since you are already familiar with the issue, would you like to send a pull request with a test reproducing the error and the fix that resolves it?

It would be wonderful if you could do that, else I will find time to get it done this weekend.

Cheers 🎉

vinitkumar added a commit that referenced this issue Oct 23, 2021
resolves #89, the params were wrong and will fail for some edge cases.
Now, all parameters are with the keyword and there are more no bugs.

Authored-by: Vinit Kumar <mail@vinitkumar.me>
Signed-off-by: Vinit Kumar <mail@vinitkumar.me>
@vinitkumar
Copy link
Owner

@mmabey The issues is fixed and release to the pypi here: pip install json2xml==3.8.4

Please upgrade your package and it should just work. I have also added a test for the case if the error every comes.

@vinitkumar
Copy link
Owner

I am closing this issues, if the issue still persists, please reopen the issue.

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

No branches or pull requests

2 participants