sanitizers / octomachinery

🤖 Invisible engine driving octobot machines. Simple, yet powerful. [DEMO BOT @ https://github.com/sanitizers/chronographer-github-app] | [tutorial @ https://tutorial.octomachinery.dev] | [docs @ https://docs.octomachinery.dev] | official web-site is at -->
https://octomachinery.dev
GNU General Public License v3.0
56 stars 12 forks source link

TypeError: __init__() got an unexpected keyword argument 'client_id' #61

Closed sentry-io[bot] closed 2 months ago

sentry-io[bot] commented 2 months ago

Sentry Issue: PATCHBACK-20

TypeError: __init__() got an unexpected keyword argument 'client_id'
  File "octomachinery/routing/webhooks_dispatcher.py", line 69, in route_github_event
    github_install = await github_app.get_installation(github_event)
  File "octomachinery/github/api/app_client.py", line 113, in get_installation
    return await self.get_installation_by_id(install_id)
  File "octomachinery/github/api/app_client.py", line 118, in get_installation_by_id
    GitHubAppInstallationModel(

Task exception was never retrieved
future: <Task finished name='Task-33452' coro=<route_github_event() done, defined at /opt/app-root/lib64/python3.9/site-packages/octomachinery/routing/webhooks_dispatcher.py:29> exception=TypeError("__init__() got an unexpected keyword argument 'client_id'")>

Upvote & Fund

Fund with Polar

webknjaz commented 2 months ago

I need to go AFK for a couple of hours, but ultimately I'm planning to apply the following patch to prevent this from happening in the future (since it's not the first time GH is suddenly updating their API responses on us w/o actually versioning the changes):

index 304c479..db5ade0 100644
--- a/octomachinery/utils/asynctools.py
+++ b/octomachinery/utils/asynctools.py
@@ -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)
@@ -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:
+            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
webknjaz commented 2 months ago

Re-deployed Chronographer and Patchback with this. Should be good now.

webknjaz commented 2 months ago

Forgot to update the hashes in lockfiles. Re-deploying and going to sleep. Will re-check Sentry later in the day...

webknjaz commented 2 months ago

Urgh.. More updates needed for the deps compat. Will have to wait another half a day.

webknjaz commented 2 months ago

Alright… I think I've updated all the right pins now.

felixfontein commented 2 months ago

It still doesn't seem to work.

webknjaz commented 2 months ago

@felixfontein show me how you tried to retrigger processing..

webknjaz commented 2 months ago

I think I saw some incomplete tracebacks. Will take a look in the morning..

felixfontein commented 2 months ago

@felixfontein show me how you tried to retrigger processing..

I removed and re-added labels for a merged PR (for example https://github.com/ansible-collections/community.general/pull/8792), or merged a PR that had backport labels.

webknjaz commented 2 months ago

Oh.. I see. I messed up @ https://github.com/sanitizers/octomachinery/commit/116222c2e0d788b2a0ea370c2a829a59b15843d1 because I applied a wrapper that returns a coroutine and didn't await that...

webknjaz commented 2 months ago

Re-deployed and checked that it doesn't traceback on the aiohttp repo anymore.