-
Notifications
You must be signed in to change notification settings - Fork 123
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
Fix ignore fields #89
Conversation
- Do not check if both the original and camel case fields are in the ignore list. Checks only if the original field is there. - Fixes the "else" clause.
@@ -37,10 +37,10 @@ def camelize(data, **options): | |||
new_key = re.sub(camelize_re, underscore_to_camel, key) | |||
else: | |||
new_key = key | |||
if key not in ignore_fields and new_key not in ignore_fields: |
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.
I think this is there for a reason, it's so you can add either the (prospective) new key, or the old key, to a list of keys to ignore.
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.
hmm, if that's the case I would still rewrite it as:
if key in ignore_fields or new_key in ignore_fields:
new_dict[key] = value
else:
new_dict[new_key] = camelize(value, **options)
It's a bit easier to read IMO
new_dict[new_key] = camelize(value, **options) | ||
else: | ||
new_dict[new_key] = value | ||
new_dict[key] = value |
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.
This change (and this change alone) will fix the issue. It will break the tests however, please see
djangorestframework-camel-case/tests.py
Line 137 in 480f67c
"ignore_me": {"noChangeRecursive": 1}, |
@stevewilliamsuk @canassa could I invite you to take a look at (and even review) #93 as an alternative solution here? It adds a new option as ignore_fields was designed to still change the key. The new option uses the name suggested by @vbabiy. |
I had to revert this merge, due to failing tests. I need to understand what's going on here more closely. |
list. Checks only if the original field is there.
Fixes #86