Print the full stack trace if a plugin failed in entities.scan

This commit is contained in:
Fabio Manganiello 2023-04-29 15:14:13 +02:00
parent 38c87ef39f
commit e919bf95ad
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -1,6 +1,7 @@
from queue import Queue, Empty from queue import Queue, Empty
from threading import Thread from threading import Thread
from time import time from time import time
from traceback import format_exception
from typing import Optional, Any, Collection, Mapping from typing import Optional, Any, Collection, Mapping
from sqlalchemy import or_, text from sqlalchemy import or_, text
@ -49,7 +50,9 @@ class EntitiesPlugin(Plugin):
""" """
entity_registry = get_entities_registry() entity_registry = get_entities_registry()
selected_types = [] selected_types = []
all_types = {e.__tablename__.lower(): e for e in entity_registry} all_types = {
e.__tablename__.lower(): e for e in entity_registry # type: ignore
}
if types: if types:
selected_types = {t.lower() for t in types} selected_types = {t.lower() for t in types}
@ -148,8 +151,9 @@ class EntitiesPlugin(Plugin):
plugin_name, result = q.get(block=True, timeout=0.5) plugin_name, result = q.get(block=True, timeout=0.5)
if isinstance(result, Exception): if isinstance(result, Exception):
self.logger.warning( self.logger.warning(
f'Could not load results from plugin {plugin_name}: {result}' 'Could not load results from plugin %s: %s', plugin_name, result
) )
self.logger.warning(''.join(format_exception(result)))
else: else:
results.append(result) results.append(result)
except Empty: except Empty:
@ -243,7 +247,10 @@ class EntitiesPlugin(Plugin):
with self._get_session(locked=True) as session: with self._get_session(locked=True) as session:
objs = session.query(Entity).filter(Entity.id.in_(entities.keys())).all() objs = session.query(Entity).filter(Entity.id.in_(entities.keys())).all()
for obj in objs: for obj in objs:
obj.meta = {**(obj.meta or {}), **(entities.get(str(obj.id), {}))} obj.meta = { # type: ignore
**dict(obj.meta or {}), # type: ignore
**(entities.get(str(obj.id), {})),
}
session.add(obj) session.add(obj)
session.commit() session.commit()