-
Notifications
You must be signed in to change notification settings - Fork 270
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: Camelize query parameters #1002
Conversation
@dobro322 thanks for the PR. nice catch, but I think this is too broad. I see that they added a middleware just recently to add that functionality. So users may have order versions or just not using the middleware, would have the wrong outcome. I think this needs to be a bit smarter about that. |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1002 +/- ##
=======================================
Coverage 98.61% 98.61%
=======================================
Files 68 68
Lines 8281 8286 +5
=======================================
+ Hits 8166 8171 +5
Misses 115 115
☔ View full report in Codecov by Sentry. |
@tfranzel any idea on how to handle it? |
I'd prefer not to, especially since this is a special case for one contrib package only.
I would probably retrieve the middleware list from django and check if that middleware is present. Based on that, I would activate the change. This also needs to be safe for older versions of the lib. |
Could there be any "unsafe" behavior if we just from django.conf import settings
def camelize_serializer_fields(result, generator, request, public):
...
camelize_parameters = (
"djangorestframework_camel_case.middleware.CamelCaseMiddleWare"
in getattr(settings, "MIDDLEWARE", [])
)
...
if camelize_parameters:
#do stuff ? the only problem i see is that if someone tries to make a child class from CamelCaseMiddleWare – we wouldn't know it by just checking if string is in array |
unsafe in the sense that when used with older version that there will be no import error or stuff like that. I believe the middleware list of strings gets automatically converted (imported) on loading. So in theory one could do We are never gonna cover every case anyway. If someone further customizes, they also have to customize the extensions. |
I noticed that when using djangorestframework-camel-case, parameters don't convert to camel case.