Better error handling for missing extensions
This commit is contained in:
parent
b5a436be4a
commit
690c829445
|
|
@ -8,10 +8,17 @@ import asyncio
|
|||
|
||||
class AsyncronQuerySet( models.QuerySet ):
|
||||
async def gather_method( self, method, *args, **kwargs ):
|
||||
mapping = {
|
||||
instance.pk: getattr( instance, method )( *args, **kwargs )
|
||||
async for instance in self
|
||||
}
|
||||
|
||||
#This functions postpones NotImplementedError(s) casued
|
||||
#by asyncron.extensions not matching, to inside asyncio.gather
|
||||
async def raise_notemp( e ): raise e
|
||||
mapping = {}
|
||||
async for instance in self:
|
||||
try:
|
||||
mapping[instance.pk] = getattr( instance, method )( *args, **kwargs )
|
||||
except NotImplementedError as e:
|
||||
mapping[instance.pk] = raise_notemp(e)
|
||||
|
||||
returns = await asyncio.gather( *list(mapping.values()), return_exceptions = True )
|
||||
for index, pk in enumerate(mapping):
|
||||
mapping[pk] = returns[index]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import collections
|
||||
import functools
|
||||
from .utils import rgetattr
|
||||
|
||||
class Extender:
|
||||
capturing_instance = None
|
||||
|
|
@ -38,11 +39,11 @@ class Extender:
|
|||
break
|
||||
if check_failed: continue
|
||||
|
||||
if any( getattr(self, k) != v for k, v in filters.items() ):
|
||||
if any( rgetattr(self, k.replace("__", ".")) != v for k, v in filters.items() ):
|
||||
continue
|
||||
|
||||
return f( self, *args, **kwargs )
|
||||
raise AttributeError(f"{self} Did not match any extensions for '{extended_name}'.")
|
||||
raise NotImplementedError(f"{self} Did not match any extensions for '{extended_name}'.")
|
||||
return run_matching_candidate
|
||||
|
||||
cls.__getattr__ = __getattr__
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user