MycroftAI/adapt

Possible bug in context merging in context.py

Opened this issue · 1 comments

I'm new to mycroft, and I started to study the codebase (great stuff!). I noticed in Adapt this bug:

adapt/adapt/context.py

Lines 73 to 88 in 7eeadeb

def merge_context(self, tag, metadata):
"""
merge into contextManagerFrame new entity and metadata.
Appends tag as new entity and adds keys in metadata to keys in
self.metadata.
Args:
tag(str): entity to be added to self.entities
metadata(object): metadata containes keys to be added to self.metadata
"""
self.entities.append(tag)
for k in metadata.keys():
if k not in self.metadata:
self.metadata[k] = k

The keys of metadata are used instead of the values in merging. I believe it should be something like

    def merge_context(self, tag, metadata):
        """
        merge into contextManagerFrame new entity and metadata.

        Appends tag as new entity and adds keys in metadata to keys in
        self.metadata.

        Args:
            tag(str): entity to be added to self.entities
            metadata(object): metadata containes keys to be added to self.metadata
        """
        self.entities.append(tag)
        for k, v in metadata.items():
            if k not in self.metadata:
                self.metadata[k] = v

I'm still not very familiar with the codebase, so sorry if I got this wrong.

Hey @theartful , thanks for the issue! It looks like we don't have any test coverage or users of this, so good eye!