Commit b5d0f55a authored by Antoine Millet's avatar Antoine Millet
Browse files

Fixed bug with user defined tags not updated by objectdb.

parent d38069c8
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ class ObjectsDB(object):
            self._nb_queries += 1
            self._update(ids, tags, tags_novalue)
            self._process_responses()
            self._update_user_defined(ids)

    def _update(self, ids=None, tags=None, tags_novalue=None):
        '''
@@ -131,6 +132,27 @@ class ObjectsDB(object):
                # Current object is a standard node:
                self._update_object(obj, tags, tags_novalue)

    def _update_user_defined(self, ids):
        '''
        Update the user defined tags (previously fetched
        by :meth:`_update_object`).
        '''

        if ids is not None:
            ids = set(ids)
        else:
            ids = set(self._objects)

        for objid in ids:
            obj = self.get_by_id(objid)

            if '__parent' in obj:
                user_tags = obj['__parent']['__user_defined_tags']
            else:
                user_tags = obj['__user_defined_tags']

            obj.update(user_tags)
    
    def _process_responses(self):
        '''
        Process the responses received from clients.
@@ -140,6 +162,7 @@ class ObjectsDB(object):
        now = datetime.now()

        for msg in msgs:
            # Update tags if received from the peer:
            if msg.get('error') is not None:
                logging.error('Error from client while getting tags')
            else:
@@ -149,11 +172,6 @@ class ObjectsDB(object):
                assert isinstance(returned, dict), 'returned tags is not a dict'
                assert isinstance(obj, TqlObject), 'data obj is not TqlObject'

                if '__parent' in obj:
                    user_tags = obj['__parent']['__user_defined_tags']
                else:
                    user_tags = obj['__user_defined_tags']

                for name, attrs in returned.iteritems():
                    obj[name] = attrs.get('value')

@@ -168,13 +186,12 @@ class ObjectsDB(object):

                    self._ttls[(obj['id'], name)] = tod

                obj.update(user_tags)

    def _update_object(self, obj, tags, tags_novalue):
        '''
        Calculate the list of tags to request for a client, and send the
        request to the client.
        '''

        parent = obj.get('__parent')

        if parent is None: