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

fix: async pagination evaluate fix for queryset object #1354

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

WellingtonNico
Copy link

Hello guys, you are doing a great job!

I found a problem using default PageNumberPagination with async endpoint returning a queryset like this:

    @route.get("/", response=list[TodoListSchema])
    @paginate(PageNumberPagination)
    async def list_todos(self, filters: TodoFilterSchema = Query()):
        todos = filters.filter(
            Todo.objects.filter(user=self.context.request.user).values("id", "title")
        )
        return todos

I was getting that error about calling sync method, so I made a small change in your PageNumberPagination and LimitOffsetPagination.
It was not a big change, I also adjusted your tests and everything is working just fine.

The reason why the error was being raised is the same as if count was called in async loop, so that change was really needed.

I don't hope you to merge my pull request, but that change is really needed and you should merge it to properly work withQuerySet object.

@WellingtonNico
Copy link
Author

WellingtonNico commented Dec 7, 2024

I forgot to mention that I also changed the way to configure page_size, more like a way I think we are already used to do in django. That way allows the frontend developer to make small queries in certain components for example.

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