From e0827d0597ebba4660ed144a89443314321e3929 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 18 Oct 2019 11:20:32 +0200 Subject: [PATCH] added __getattribute__ to have acces to not implemented methods of pymongo db --- pype/ftrack/lib/custom_db_connector.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pype/ftrack/lib/custom_db_connector.py b/pype/ftrack/lib/custom_db_connector.py index 931b46fc00..102cbe2526 100644 --- a/pype/ftrack/lib/custom_db_connector.py +++ b/pype/ftrack/lib/custom_db_connector.py @@ -49,14 +49,12 @@ def check_active_table(func): @functools.wraps(func) def decorated(obj, *args, **kwargs): if not obj.active_table: - raise NotActiveTable("Active table is not set. (This is bug)") + raise NotActiveTable() return func(obj, *args, **kwargs) - return decorated class DbConnector: - log = logging.getLogger(__name__) timeout = 1000 @@ -72,8 +70,19 @@ class DbConnector: self.active_table = table_name def __getitem__(self, key): + # gives direct access to collection withou setting `active_table` return self._database[key] + def __getattribute__(self, attr): + # not all methods of PyMongo database are implemented with this it is + # possible to use them too + try: + return super(DbConnector, self).__getattribute__(attr) + except AttributeError: + if self.active_table is None: + raise NotActiveTable() + return self._database[self.active_table].__getattribute__(attr) + def install(self): """Establish a persistent connection to the database""" if self._is_installed: