From 89560e7c38eebde78e1b7b5c3ff662a8b0613569 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 29 May 2022 23:59:46 +0200 Subject: [PATCH] Only include entities associated to enabled plugins or with no plugins in `entities.get` --- platypush/plugins/entities/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/entities/__init__.py b/platypush/plugins/entities/__init__.py index acf7a1205..e600a2d49 100644 --- a/platypush/plugins/entities/__init__.py +++ b/platypush/plugins/entities/__init__.py @@ -3,8 +3,10 @@ from threading import Thread from time import time from typing import Optional, Any, Collection, Mapping +from sqlalchemy import or_ from sqlalchemy.orm import make_transient +from platypush.config import Config from platypush.context import get_plugin, get_bus from platypush.entities import Entity, get_plugin_entity_registry, get_entities_registry from platypush.message.event.entities import EntityUpdateEvent, EntityDeleteEvent @@ -57,8 +59,18 @@ class EntitiesPlugin(Plugin): selected_types = entity_types.keys() db = self._get_db() + enabled_plugins = list( + { + *Config.get_plugins().keys(), + *Config.get_backends().keys(), + } + ) + with db.get_session() as session: - query = session.query(Entity) + query = session.query(Entity).filter( + or_(Entity.plugin.in_(enabled_plugins), Entity.plugin.is_(None)) + ) + if selected_types: query = query.filter(Entity.type.in_(selected_types)) if plugins: