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

Adding async support to InheritanceManager/InheritanceQuerySet #544

Open
microHoffman opened this issue Nov 13, 2022 · 0 comments
Open

Adding async support to InheritanceManager/InheritanceQuerySet #544

microHoffman opened this issue Nov 13, 2022 · 0 comments

Comments

@microHoffman
Copy link

Problem

Hey, since Django ORM is starting to support async more and more, I'm wondering if you guys thought about adding async support to InheritanceManager (and InheritanceQuerySet respectively)?

Environment

  • Django Model Utils version: 4.2.0
  • Django version: 4.1
  • Python version: 3.10
  • Other libraries used, if any: not-relevant

Code examples

So far I was thinking of primitive solution to this problem and I've ended up with something like this, but I have not tested it yet (hopefully will get to testing it in few days). Do you think it should work, or is there some bigger problem about integrating async support to InheritanceManager?

class ExtendedInheritanceQuerySet(InheritanceQuerySet):
    """InheritanceQuerySet from django-model-utils extended for async methods."""

    async def aselect_subclasses(self, *subclasses):
        return await sync_to_async(self.select_subclasses)(*subclasses)

    async def aget_subclass(self, *args, **kwargs):
        return await sync_to_async(self.get_subclass)(*args, **kwargs)


class ExtendedInheritanceManager(InheritanceManager):
    """InheritanceManager from django-model-utils extended for async methods."""

    # todo also possible to create manager dynamically using `from_queryset` or `as_manager`

    _queryset_class = ExtendedInheritanceQuerySet

    async def aselect_subclasses(self, *subclasses):
        return await self.get_queryset().aselect_subclasses(*subclasses)

    async def aget_subclass(self, *args, **kwargs):
        return await self.get_queryset().aget_subclass(*args, **kwargs)
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

No branches or pull requests

1 participant