Skip to content

Commit

Permalink
🚑 Disregard unmapped installation model attrs
Browse files Browse the repository at this point in the history
Log any new attributes that GitHub added to their API responses
without any prior communication so that they could be observed in
Sentry and integrated later on.

This time, the attribute GH started attaching is `client_id`.

Fixes #61
  • Loading branch information
webknjaz committed Aug 24, 2024
1 parent 70a7fe5 commit 97da1e9
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion octomachinery/utils/asynctools.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
"""Asynchronous tools set."""

from functools import wraps
from inspect import signature as _inspect_signature
from logging import getLogger as _get_logger
from operator import itemgetter

from anyio import create_queue
from anyio import create_task_group as all_subtasks_awaited


logger = _get_logger(__name__)


def auto_cleanup_aio_tasks(async_func):
"""Ensure all subtasks finish."""
@wraps(async_func)
Expand Down Expand Up @@ -86,6 +91,24 @@ async def amap(callback, async_iterable):

def dict_to_kwargs_cb(callback):
"""Return a callback mapping dict to keyword arguments."""
cb_arg_names = set(_inspect_signature(callback).parameters.keys())

async def callback_wrapper(args_dict):
return await try_await(callback(**args_dict))
excessive_arg_names = set(args_dict.keys()) - cb_arg_names
filtered_args_dict = {
arg_name: arg_value for arg_name, arg_value in args_dict.items()
if arg_name not in excessive_arg_names
} if excessive_arg_names else args_dict
if excessive_arg_names:
logger.warning(
'Excessive arguments passed to callback %(callable)s',
{'callable': callback},
extra={
'callable': callback,
'excessive-arg-names': excessive_arg_names,
'passed-in-args': args_dict,
'forwarded-args': filtered_args_dict,
},
)
return await try_await(callback(**filtered_args_dict))
return callback_wrapper

0 comments on commit 97da1e9

Please sign in to comment.