-
Notifications
You must be signed in to change notification settings - Fork 766
Fix distinct bug #290
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 distinct bug #290
Conversation
@spockNinja #194 or #224 do not fix this issue. Distinct and non-distinct querysets cannot be combined, assertion in Django prevents this. Really needing distinct queries, I resorted to casting the qs to a list before returning it at the end of the resolver function. This prevents BTW what is the use case of enforced |
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.
A few discussion points. Also, the new test is currently failing. See https://travis-ci.org/graphql-python/graphene-django/jobs/286635259#L744
graphene_django/fields.py
Outdated
@@ -90,6 +90,10 @@ def connection_resolver(cls, resolver, connection, default_manager, max_limit, | |||
if isinstance(iterable, QuerySet): | |||
if iterable is not default_manager: | |||
default_queryset = maybe_queryset(default_manager) | |||
if default_queryset.query.distinct and not iterable.query.distinct: |
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.
How about moving this logic into merge_querysets
? Then any of the subclasses that use that will get this fix for free.
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.
Good idea, did that
graphene_django/fields.py
Outdated
@@ -90,6 +90,10 @@ def connection_resolver(cls, resolver, connection, default_manager, max_limit, | |||
if isinstance(iterable, QuerySet): | |||
if iterable is not default_manager: | |||
default_queryset = maybe_queryset(default_manager) | |||
if default_queryset.query.distinct and not iterable.query.distinct: | |||
iterable = iterable.distinct() |
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.
How does this behave when the other distinct call had field args? (queryset.distinct('field_1', 'field_2')
)
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 honestly have no idea. From my superficial understanding it should be fine :). Do I understand it correctly that this is only possible when using postgres backends?
graphene_django/tests/test_query.py
Outdated
|
||
result = schema.execute(query) | ||
assert not result.errors | ||
print(result.data) |
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.
Lets be sure to drop this print
once the test is working.
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.
Done
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.
the print is still there :)
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.
Ah sorry, missed your comment - thanks, will fix now!
Updated the PR. The travis check seems to rebase this on top of master but my test was written against django-graphene 1.x (4 parameters to resolve functions). Is there a way to make travis test this against the 1.x branch and once everyone is fine with the PR we adapt it to 2.0 and merge an updated PR there? Or is the 1.x line no longer supported? |
Since this PR is merging into There also appears to be a merge conflict in Thanks a bunch for your work. Let's get those last things fixed up and I'll pass this on to the owner for a final review. 😄 |
@danyx23 Are you still working on this? If not I'd be happy to pick it where you've left it and adapt it for the current master. @jussih The default |
Ah damn, I totally forgot about this. Yes, I'll rebase against master and send an updated PR! |
…d involving a query with inner join and distinct that is then filtered and would be combined with a filtered queryset that is not distinct.
04f5770
to
4d41160
Compare
Rebased against master, tests are green. Please let me know if you are happy for this to merge. (It's the first time I rebased a github PR, I should probably have created a new one to preserve the history of the old commits, sorry abou that) |
Do you mind merging this or do you consider it blocked because the coverage decreased by 0.08%? |
class Query(graphene.ObjectType): | ||
films = DjangoConnectionField(FilmType) | ||
|
||
# def resolve_all_reporters_with_berlin_films(self, args, context, info): |
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.
sorry last one :) Is this needed?
I guess after resolving this @spockNinja or @syrusakbary can merge :)
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.
There might be a way to integrate it with the existing test suite but I didn't see a straightforward way to construct a query that would lead to one "half" of the resulting query being distinct and the other not. Doing it in this way keeps the addition localized to where it is needed. If you have a suggestion on how to integrate it with the existing model instead please let me know!
The PR looks good 👍 . Merging |
This adds a test case and fixes /issues/289. Please review and let me know if anythin should change, I'm not an expert in either graphql nor django :)