Hi there, Just a quick assumption, code duplication could be the reason why the follow parameter and the _handle_redirects method was not implemented on the AsyncClient as per the ticket #34757, if my assumption is wrong, no big deal.
Kind regards. On Sat, Aug 5, 2023 at 8:45 PM Jon Janzen <j...@jonjanzen.com> wrote: > Hey there, > > > Not that much with a 50 lines function. that could easily become a > maintenance burden. > > what do you think about code duplication of async function ? (please > point me to existing threads if the discussion already occurred) > > I flagged this problem in > https://forum.djangoproject.com/t/asyncifying-django-contrib-auth-and-signals-and-maybe-sessions/18770 > and before that in > https://groups.google.com/g/django-developers/c/T8zBnYO78YQ > > There doesn't really seem to be a good resolution to this problem right > now, unfortunately :( > > > why do we see almost no sync wrapper (async_to_sync) in django's code > base ? Is that a best practice ? > > I can't give an authoritative answer but my intuition is that we are still > in the early stages of the process of asyncifying everything and we're at > the second bullet point from DEP-009 ("Sync-native, with an async wrapper") > and haven't yet gotten started on an async-native implementation with a > sync wrapper. > > There are a few key things missing from core django before that's > possible. Some of which are laid out in that forum thread I linked above, > others are listed directly in the DEP like the ORM being fully asyncified > (right now it's just an async wrapper around sync code) which is somewhat > blocked on async database implementations (psycopg3 being the first one > supported). > > I don't really have any answers for you, just some more thoughts. Hope > that's helpful! > > Jon > On Saturday, August 5, 2023 at 10:23:00 AM UTC-7 Olivier Tabone wrote: > >> Hi all, >> >> While working on async related tickets (eg #34717, and more recently >> #34757) I noticed code duplication between sync and async version of same >> functions: >> >> some examples: (no personal offense ❤️) >> >> >> - acheck_password / check_password in base_user.py >> >> <https://github.com/django/django/blob/e4a5527d1dc2f8183883931560f3a6dcdef0ab0c/django/contrib/auth/base_user.py#L126> >> - get_many() / a_getmany() in cache/backends/base.py >> >> <https://github.com/django/django/blob/e4a5527d1dc2f8183883931560f3a6dcdef0ab0c/django/core/cache/backends/base.py#L208> >> >> and of course the way I fixed #34717, now we have some code duplication >> in aget_object_or_404 >> <https://github.com/olibook/django/blob/b9473cac65190822e7c94f695f1f7b4d5b49502a/django/shortcuts.py#L92> >> / aget_list_or_404 >> <https://github.com/olibook/django/blob/b9473cac65190822e7c94f695f1f7b4d5b49502a/django/shortcuts.py#L134C11-L134C27> >> >> As I'm working on #34757, and following this pattern, there would be some >> duplication of the TestClient._handle_redirects >> <https://github.com/olibook/django/blob/a564f44350afc4823b9ff6eb14c56e8793ed4b31/django/test/client.py#L1170> >> method to support the async case. >> >> I'm kind of ok when duplicating a 3 lines function. Not that much with a >> 50 lines function. that could easily become a maintenance burden. >> >> I've read DEP-009 >> <https://github.com/django/deps/blob/main/accepted/0009-async.rst>a few >> times and the plan at the time was (quoted from the "Technical Overview") >> >> Each feature will go through three stages of implementation: >> >> - Sync-only (where it is today) >> - Sync-native, with an async wrapper >> - Async-native, with a sync wrapper >> >> >> I was wondering: >> 1- why do we see almost no sync wrapper (async_to_sync) in django's code >> base ? Is that a best practice ? >> 2- what do you think about code duplication of async function ? (please >> point me to existing threads if the discussion already occurred) What is Ok >> / What is not ok ? Is there some cleanup to be done ? >> >> >> Cheers, >> >> - Olivier Tabone >> >> >> >> >> >> -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/be3a9dba-2702-4fbd-baef-c49587892616n%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/be3a9dba-2702-4fbd-baef-c49587892616n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CA%2Bniz3jdeob-EmbgA6P%2BtSww%3DE8x%3DxJ8iKVEx-ev_GtPsZ0NVA%40mail.gmail.com.