Skip to content

Commit

Permalink
Merge pull request #7334 from ducminh-phan/fix-RedisTrackerStore
Browse files Browse the repository at this point in the history
Fix incorrect attribute for key prefix in RedisTrackerStore
  • Loading branch information
federicotdn authored Nov 30, 2020
2 parents a099316 + 799641d commit 5d8b02c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog/7306.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an erroneous attribute for Redis key prefix in `rasa.core.tracker_store.RedisTrackerStore`: 'RedisTrackerStore' object has no attribute 'prefix'.
20 changes: 16 additions & 4 deletions rasa/core/tracker_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,30 @@ def save(self, tracker, timeout=None):
timeout = self.record_exp

serialised_tracker = self.serialise_tracker(tracker)
self.red.set(self.prefix + tracker.sender_id, serialised_tracker, ex=timeout)
self.red.set(
self.key_prefix + tracker.sender_id, serialised_tracker, ex=timeout
)

def retrieve(self, sender_id: Text) -> Optional[DialogueStateTracker]:
stored = self.red.get(self.prefix + sender_id)
"""Retrieves tracker for the latest conversation session.
The Redis key is formed by appending a prefix to sender_id.
Args:
sender_id: Conversation ID to fetch the tracker for.
Returns:
Tracker containing events from the latest conversation sessions.
"""
stored = self.red.get(self.key_prefix + sender_id)
if stored is not None:
return self.deserialise_tracker(sender_id, stored)
else:
return None

def keys(self) -> Iterable[Text]:
"""Returns keys of the Redis Tracker Store"""
return self.red.keys(self.prefix + "*")
"""Returns keys of the Redis Tracker Store."""
return self.red.keys(self.key_prefix + "*")


class DynamoTrackerStore(TrackerStore):
Expand Down
11 changes: 3 additions & 8 deletions tests/shared/core/test_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,15 @@


class MockRedisTrackerStore(RedisTrackerStore):
# skipcq:PYL-W0231
# can't call call super init since it would init a redis connection
def __init__(self, _domain: Domain) -> None:
super().__init__(_domain)

# Patch the Redis connection in RedisTrackerStore using fakeredis
self.red = fakeredis.FakeStrictRedis()
self.record_exp = None

# added in redis==3.3.0, but not yet in fakeredis
self.red.connection_pool.connection_class.health_check_interval = 0

# Defined in RedisTrackerStore but needs to be added for the MockRedisTrackerStore
self.prefix = "tracker:"

TrackerStore.__init__(self, _domain)


def stores_to_be_tested():
temp = tempfile.mkdtemp()
Expand Down

0 comments on commit 5d8b02c

Please sign in to comment.