diff --git a/changelog/7306.bugfix.md b/changelog/7306.bugfix.md new file mode 100644 index 000000000000..705d5fba3c7d --- /dev/null +++ b/changelog/7306.bugfix.md @@ -0,0 +1 @@ +Fix an erroneous attribute for Redis key prefix in `rasa.core.tracker_store.RedisTrackerStore`: 'RedisTrackerStore' object has no attribute 'prefix'. diff --git a/rasa/core/tracker_store.py b/rasa/core/tracker_store.py index 3a46c6891348..5f51109491bc 100644 --- a/rasa/core/tracker_store.py +++ b/rasa/core/tracker_store.py @@ -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): diff --git a/tests/shared/core/test_trackers.py b/tests/shared/core/test_trackers.py index 8f68c917c572..3307e3b1677a 100644 --- a/tests/shared/core/test_trackers.py +++ b/tests/shared/core/test_trackers.py @@ -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()