Skip to content

Fix select_related with filtering #224

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
merged 4 commits into from
Nov 13, 2017
Merged

Fix select_related with filtering #224

merged 4 commits into from
Nov 13, 2017

Conversation

camd
Copy link
Contributor

@camd camd commented Jul 21, 2017

I must admit, I don't totally see the need for this union between the default_queryset and queryset but through experimentation, I have found that if the order of the union is reversed, it will preserve the select_related and prefetch_related. It has the same effect of finding the union of records returned. The list is identical.

So I hope this change doesn't break something I'm not aware of. :)

This is an attempt to fix #179

@coveralls
Copy link

coveralls commented Jul 21, 2017

Coverage Status

Coverage remained the same at 92.721% when pulling 146ce58 on camd:fix-select-related into 0588f89 on graphql-python:master.

@coveralls
Copy link

coveralls commented Jul 21, 2017

Coverage Status

Coverage remained the same at 92.721% when pulling 146ce58 on camd:fix-select-related into 0588f89 on graphql-python:master.

4 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.721% when pulling 146ce58 on camd:fix-select-related into 0588f89 on graphql-python:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.721% when pulling 146ce58 on camd:fix-select-related into 0588f89 on graphql-python:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.721% when pulling 146ce58 on camd:fix-select-related into 0588f89 on graphql-python:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.721% when pulling 146ce58 on camd:fix-select-related into 0588f89 on graphql-python:master.

@syrusakbary syrusakbary force-pushed the master branch 2 times, most recently from bdc7189 to f93251b Compare September 1, 2017 08:12
@spockNinja
Copy link
Contributor

@syrusakbary Same fix as #194, just specific to filter fields. Looks fine to me.

@jancespivo
Copy link

Hi, IMO this code violates DRY principle and should be refactorized. The DjangoFilterConnectionField is inherited from DjangoConnectionField where the code is ok (in classmethod merge_queryset). I agree with this fix (it's the same fix as mine in duplicate #272 ) but I think it is definitely not a good final solution.

@camd
Copy link
Contributor Author

camd commented Oct 3, 2017

Thanks for accepting the fix! I'm not able to merge it, so I'll leave that to the project collaborators. Thanks everyone. :)

@syrusakbary
Copy link
Member

I agree with @jancespivo that the code needs to be refactored, but we can do it in a separate PR.

The change looks good, but I think before merging the PR should include tests ensuring that the issue is not repeated in future releases.

@coveralls
Copy link

coveralls commented Oct 10, 2017

Coverage Status

Coverage decreased (-0.2%) to 92.79% when pulling 7a110ab on camd:fix-select-related into f93251b on graphql-python:master.

@spockNinja
Copy link
Contributor

7a110ab should address everyone's concerns. Using super to use DjangoConnectionField's default implementation. Since the base class's implementation was tested in #194 then it is tested here.

Tests are failing, but it's unrelated. I'm looking into those failures in a separate PR.

@coveralls
Copy link

coveralls commented Oct 14, 2017

Coverage Status

Coverage remained the same at 92.999% when pulling 1d76db8 on camd:fix-select-related into 283bccf on graphql-python:master.

@spockNinja
Copy link
Contributor

Now that the failing test in master is fixed, this PR is ✅.

@syrusakbary Ready for merge, and I can close several duplicate issues/PRs for this bug.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 93.014% when pulling 95e28ba on camd:fix-select-related into dfa0a06 on graphql-python:master.

2 similar comments
@coveralls
Copy link

coveralls commented Nov 13, 2017

Coverage Status

Coverage remained the same at 93.014% when pulling 95e28ba on camd:fix-select-related into dfa0a06 on graphql-python:master.

@coveralls
Copy link

coveralls commented Nov 13, 2017

Coverage Status

Coverage remained the same at 93.014% when pulling 95e28ba on camd:fix-select-related into dfa0a06 on graphql-python:master.

@syrusakbary syrusakbary merged commit 9e26aaf into graphql-python:master Nov 13, 2017
@camd
Copy link
Contributor Author

camd commented Nov 13, 2017

Thanks for the merge! :)

@camd camd deleted the fix-select-related branch November 13, 2017 16:42
@urbandove
Copy link
Contributor

urbandove commented Nov 13, 2017

There's an issue with this merge - if a class is subclassing DjangoFilterConnectionField and a queryset is returned from resolve_schema_field the super(cls,cls) refers back to DjangoFilterConnectionField and has an endless loop.

other people fixed this issue by copying the code from the merge_queryset
queryset = queryset & default_queryset

but it seems we can keep this change and have only one place for that code by replacing
queryset = super(cls, cls).merge_querysets(default_queryset, queryset)
with
queryset = super(DjangoFilterConnectionField, cls).merge_querysets(default_queryset, queryset)

edmorley added a commit to mozilla/treeherder that referenced this pull request Jul 26, 2018
edmorley added a commit to mozilla/treeherder that referenced this pull request Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DjangoConnectionField discards select_related
6 participants