jazzband / django-taggit

Simple tagging for django
https://django-taggit.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.27k stars 623 forks source link

Add support for new async api #865

Open rasca opened 11 months ago

rasca commented 11 months ago

Django 4.2 added support for async m2m manipulation directly via aadd, aset, aclear, aremove. Since taggit is based in that API it would be nice to also support it.

For now we can just:

from channels.db import database_sync_to_async

[...]

await database_sync_to_async(mymodel.tags.add)('mytag')
rtpg commented 9 months ago

Not sure what we need to do exactly here, I would hope that models.Manager would get us this "for free", but seems like it might not. We'll likely need to do some work to add some tests on this front as well. Bit of a chill weekend commit, probably!

rtpg commented 1 week ago

How Django implements aadd....

        async def aadd(self, *objs, bulk=True):
            return await sync_to_async(self.add)(*objs, bulk=bulk)

I think it would make sense for us to add async variants to methods like add and set and remove on _TaggableManager (in taggit/managers.py) that just do a similar sync_to_async strategy like above (with similar naming).

Doing that should "just work" according to my reading of how all this stuff works.

This only really should target Django 4.2+ IMO