Skip to content
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

Use the default SearchQuerySet class without overriding get_queryset #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

w0rp
Copy link

@w0rp w0rp commented Jun 17, 2016

Overriding get_queryset causes problems when using YourManager.from_queryset(YourQuerySetClass) instead of return an instances of YourQuerySetClass, it will return an instance of SearchQuerySet. By changing the implementation of the SearchManager class, you can support this use case, by not overriding the get_queryset method so it will replace the BaseManager method, so it can then return the correct QuerySet subclass.

Overriding get_queryset causes problems when using `YourManager.from_queryset(YourQuerySetClass)` instead of return an instances of `YourQuerySetClass`, it will return an instance of `SearchQuerySet`. By changing the implementation of the `PGSearchManager` class, you can support this use case, by not overriding the `get_queryset` method so it will replace the `BaseManager` method, so it can then return the correct `QuerySet` subclass.
@w0rp
Copy link
Author

w0rp commented Jun 17, 2016

I haven't tested this against all Django versions, but it should work on 1.8. I ran into this when I had a subclass of SearchQuerySet, a manager which was a sub class of SearchManager, and another sub class.

class MyBaseManager(SearchManager):
    pass

class MyQuerySet(SearchQuerySet):
    pass

class AnotherManager(MyBaseManager.from_queryset(MyQuerySet)):
   pass

With the code as it is now, the get_queryset method for AnotherManager will return just an instance of SearchQuerySet. With these changes here, it will return an instance of MyQuerySet.

@w0rp
Copy link
Author

w0rp commented Jun 17, 2016

If the tests fail on older Django versions, it should be possible to detect the Django version and apply this patch differently by calling super() with the attribute set in versions which support the attribute, and falling back on the current implementation of the method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant