> On 9 May 2019, at 22:06, Andrew Godwin <and...@aeracode.org> wrote:
> 
> Jannis suggested what I think might be a nicer approach on Twitter, which is 
> to add an async "proxy object" to access methods with, e.g.:
> 
> cache.get("foo")
> cache.async.get("foo")
> 
> This is still explicit but looks less ugly, and gives us a way in future to 
> make some modules transition to async-by-default (by e.g. supplying 
> cache.sync.get). What do you think?


I don't think it makes a significant difference from a readability perspective 
in this example. It does have some advantages, though:

- It could be easier to implement a sync version based on the async one, or 
vice-versa, if each one has its own class. It will probably be more DRY.
- It could also be a bit more usable by developers, especially in IDEs

Also it could provide an alternative solution for the async attribute access 
problem: `model_instance.async.related_field` could be a Future that, when 
awaited, resolves to the related field. So you could `await 
model_instance.async.related_field` instead of having to `select_related`. To 
be honest I didn't investigate all the consequences of this idea. It seemed 
worth mentioning, though, even if it turns out to be impractical :-)

We've always considered that implicit queries on attribute access were an 
intractable problem. I said it on stage an DjangoCon US 2013. I'm now wondering 
if I was wrong all along! In an async ORM context, every time we traverse a 
relation, we could create a Future that would execute the query and resolve to 
its result. This would require one await per SQL query so we'd still get the 
benefit of making queries explicit, although to a lesser extent than with an 
explicit select/prefetch_related.

-- 
Aymeric.

-- 
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 post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/258CBCB2-2456-439F-82DF-E8760AE5EEF0%40polytechnique.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to