From 664a2404fa636fc02e196349bc3c67384cb8f273 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 23 Apr 2020 07:39:22 +0200 Subject: [PATCH] simplify publish function --- src/risotto/dispatcher.py | 69 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/src/risotto/dispatcher.py b/src/risotto/dispatcher.py index e9244c7..2572a88 100644 --- a/src/risotto/dispatcher.py +++ b/src/risotto/dispatcher.py @@ -147,40 +147,39 @@ class PublishDispatcher: check_role, kwargs, function_objs) - else: - try: - async with self.pool.acquire() as connection: - await connection.set_type_codec( - 'json', - encoder=dumps, - decoder=loads, - schema='pg_catalog' - ) - risotto_context.connection = connection - async with connection.transaction(): - return await self.launch(version, - message, - risotto_context, - check_role, - kwargs, - function_objs) - except CallError as err: - raise err - except Exception as err: - # if there is a problem with arguments, just send an error and do nothing - if get_config()['global']['debug']: - print_exc() - async with self.pool.acquire() as connection: - await connection.set_type_codec( - 'json', - encoder=dumps, - decoder=loads, - schema='pg_catalog' - ) - risotto_context.connection = connection - async with connection.transaction(): - await log.error_msg(risotto_context, kwargs, err) - raise err + try: + async with self.pool.acquire() as connection: + await connection.set_type_codec( + 'json', + encoder=dumps, + decoder=loads, + schema='pg_catalog' + ) + risotto_context.connection = connection + async with connection.transaction(): + return await self.launch(version, + message, + risotto_context, + check_role, + kwargs, + function_objs) + except CallError as err: + raise err + except Exception as err: + # if there is a problem with arguments, just send an error and do nothing + if get_config()['global']['debug']: + print_exc() + async with self.pool.acquire() as connection: + await connection.set_type_codec( + 'json', + encoder=dumps, + decoder=loads, + schema='pg_catalog' + ) + risotto_context.connection = connection + async with connection.transaction(): + await log.error_msg(risotto_context, kwargs, err) + raise err class Dispatcher(register.RegisterDispatcher, @@ -329,8 +328,6 @@ class Dispatcher(register.RegisterDispatcher, if key in function_obj['arguments']: kw[key] = value - - kw['risotto_context'] = risotto_context returns = await function(self.injected_self[function_obj['module']], **kw) if risotto_context.type == 'rpc':