Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DjangoFilterBackend.get_filterset_kwargs doesn't modify data dict while iterating #580

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

Merged
sliverc merged 7 commits into django-json-api:master from mindblight:feature/fix-skipped-filter-param
Mar 2, 2019
Merged

DjangoFilterBackend.get_filterset_kwargs doesn't modify data dict while iterating #580

sliverc merged 7 commits into django-json-api:master from mindblight:feature/fix-skipped-filter-param
Mar 2, 2019

Conversation

Copy link
Contributor

@mindblight mindblight commented Feb 24, 2019
edited
Loading

It looks like DjangoFilterBackend.get_filterset_kwargs reused the same dictionary for the original (filter[something]) keys, the converted (something) keys, and the extra params (include or page). By calling data[key] = val in while iterating data.items(), the indexes can be incorrectly changed: https://stackoverflow.com/questions/6777485/modifying-a-python-dict-while-iterating-over-it

Example

With the path: /api/products?filter[organization]=44cbbad6-d418-4129-8093-731637d5013b&filter[archived]=False&filter[productType.key]=biomass&include=images,product_type, different filter params were ignored based on their order in the param string.

  • filter[productType.key]=...&filter[organization]=...&filter[archived]=False&include=images,product_type
    • ignores filter[archived]
  • filter[productType.key]=...&filter[organization]=...&filter[archived]=False&include=images,product_type
    • ignores filter[organization]
  • filter[archived]=False&filter[productType.key]=...&filter[organization]=...&include=images,product_type
    • ignores filter[organization]
  • filter[archived]=False&filter[organization]=...&filter[productType.key]=...&include=images,product_type
    • ignores filter[productType.key]
  • filter[organization]=...&filter[archived]=False&filter[productType.key]=...&include=images,product_type
    • ignores filter[productType.key]
  • filter[organization]=...&filter[productType.key]=...&filter[archived]=False&include=images,product_type
    • ignores filter[archived]
  • filter[organization]=...&filter[productType.key]=...&filter[archived]=False
    • works perfectly

Fixes #

Description of the Change

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • documentation updated
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS

@mindblight mindblight changed the title (削除) switched DjangoFilterBackend.get_filterset_kwargs to populate new dat... (削除ここまで) (追記) DjangoFilterBackend.get_filterset_kwargs doesn't modify data dict while iterating (追記ここまで) Feb 24, 2019
Copy link
Contributor Author

The fix doesn't return other params in data. It didn't seem to have an impact, but I'd love to have someone who knows the code base comment.

Copy link

codecov bot commented Feb 24, 2019

Codecov Report

Merging #580 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@ Coverage Diff @@
## master #580 +/- ##
==========================================
- Coverage 95.64% 95.64% -0.01% 
==========================================
 Files 55 55 
 Lines 2850 2849 -1 
==========================================
- Hits 2726 2725 -1 
 Misses 124 124
Impacted Files Coverage Δ
rest_framework_json_api/django_filters/backends.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75e2f82...b478f06. Read the comment docs.

Copy link

codecov bot commented Feb 24, 2019
edited
Loading

Codecov Report

Merging #580 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@ Coverage Diff @@
## master #580 +/- ##
==========================================
+ Coverage 95.64% 95.65% +<.01% 
==========================================
 Files 55 55 
 Lines 2850 2856 +6 
==========================================
+ Hits 2726 2732 +6 
 Misses 124 124
Impacted Files Coverage Δ
rest_framework_json_api/django_filters/backends.py 100% <100%> (ø) ⬆️
example/tests/test_filters.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30ca94b...8eca777. Read the comment docs.

Copy link
Contributor

@n2ygk n2ygk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching my bug!

@sliverc can you take a second look just to make sure?

@n2ygk n2ygk requested a review from sliverc February 24, 2019 14:26
Copy link
Member

@sliverc sliverc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mindblight
Thanks for your pull requests. The change looks good!
To ensure this fix for the future could you add a test reproducing the issue?
A changelog entry would be good as well and add yourself to AUTHORS if you like. Thanks.

Arion Sprague added 3 commits February 25, 2019 10:53
...ed-filter-param
* upstream/master:
 Clarify docs on controlling compound documents (#579)
 Update isort from 4.3.4 to 4.3.5 (#581)
Copy link
Contributor Author

@sliverc Done! It seems like 4 params is the magic number for this bug to show up.

Copy link
Contributor Author

@sliverc, It looks like the codecov checks are hanging for some reason. Is there any way to re-trigger those, or merge without them?

@sliverc sliverc merged commit 272a752 into django-json-api:master Mar 2, 2019
Copy link
Member

sliverc commented Mar 2, 2019

@mindblight Thanks. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@sliverc sliverc sliverc approved these changes

@n2ygk n2ygk n2ygk approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /