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

Error when a key is a number #35

Open
jacobg opened this issue Nov 29, 2018 · 0 comments
Open

Error when a key is a number #35

jacobg opened this issue Nov 29, 2018 · 0 comments

Comments

@jacobg
Copy link

jacobg commented Nov 29, 2018

The job of django-rest-framework-xml is to convert dictionaries to xml. It is valid for a python dictionary to contain a key which is either an integer or the string representation of an integer. And it renders find to json. But the xml renderer fails: (i) if the key is an integer, sax will raise an exception; (2) if it's a string rep of an integer, it will render to invalid xml because an xml tag name cannot be a number.

I propose we slightly modify the renderer's _to_xml method to add this code when iterating each key:

                attributes = {}
                if isinstance(key, six.integer_types):
                    attributes = {'number': force_text(key)}
                    key = 'element'

Does that seem reasonable?

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

1 participant