Better error handling for missing extensions

This commit is contained in:
Oracle 2024-11-18 02:54:39 +01:00
parent b5a436be4a
commit 690c829445
3 changed files with 15 additions and 7 deletions

View File

@ -8,10 +8,17 @@ import asyncio
class AsyncronQuerySet( models.QuerySet ): class AsyncronQuerySet( models.QuerySet ):
async def gather_method( self, method, *args, **kwargs ): async def gather_method( self, method, *args, **kwargs ):
mapping = {
instance.pk: getattr( instance, method )( *args, **kwargs ) #This functions postpones NotImplementedError(s) casued
async for instance in self #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 ) returns = await asyncio.gather( *list(mapping.values()), return_exceptions = True )
for index, pk in enumerate(mapping): for index, pk in enumerate(mapping):
mapping[pk] = returns[index] mapping[pk] = returns[index]

View File

@ -1,5 +1,6 @@
import collections import collections
import functools import functools
from .utils import rgetattr
class Extender: class Extender:
capturing_instance = None capturing_instance = None
@ -38,11 +39,11 @@ class Extender:
break break
if check_failed: continue 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 continue
return f( self, *args, **kwargs ) 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 return run_matching_candidate
cls.__getattr__ = __getattr__ cls.__getattr__ = __getattr__

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='asyncron', name='asyncron',
version='0.1.4', version='0.1.5',
packages=find_packages(), packages=find_packages(),
#include_package_data=True, # Include static files from MANIFEST.in #include_package_data=True, # Include static files from MANIFEST.in
install_requires=[ install_requires=[