From a89c8f68cd57f2595bd8427f87ac93fea9fa358d Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 26 Apr 2025 11:51:13 +0200 Subject: [PATCH] Add unit test for TickerHandler store_key fix --- CHANGELOG.md | 3 +++ evennia/scripts/tests.py | 14 ++++++++++++++ evennia/scripts/tickerhandler.py | 9 ++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1508f31b85..38f99c3d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,8 @@ This upgrade requires running `evennia migrate` on your existing database - [Fix][pull3744]: Fix for format strings not getting picked up in i18n (JohnFi) - [Fix][pull3743]: Log full stack trace on failed object creation (aMiss-aWry) - [Fix][pull3747]: TutorialWorld bridge-room didn't correctly randomize weather effects (SpyrosRoum) +- [Fix][pull3765]: Storing TickerHandler `store_key` in a db attribute would not + work correctly (0xDEADFED5) - Fix: `options` setting `NOPROMPTGOAHEAD` was not possible to set (Griatch) - Fix: Make `\\` properly preserve one backlash in funcparser (Griatch) - Fix: The testing 'echo' inputfunc didn't work correctly; now returns both args/kwargs (Griatch) @@ -70,6 +72,7 @@ This upgrade requires running `evennia migrate` on your existing database [pull3743]: https://github.com/evennia/evennia/pull/3743 [pull3744]: https://github.com/evennia/evennia/pull/3744 [pull3747]: https://github.com/evennia/evennia/pull/3747 +[pull3765]: https://github.com/evennia/evennia/pull/3765 [issue3688]: https://github.com/evennia/evennia/issues/3688 [issue3687]: https://github.com/evennia/evennia/issues/3687 diff --git a/evennia/scripts/tests.py b/evennia/scripts/tests.py index e1277b8584..f7f3eaec43 100644 --- a/evennia/scripts/tests.py +++ b/evennia/scripts/tests.py @@ -45,6 +45,20 @@ class TestTickerHandler(TestCase): th = TickerHandler() th.remove(callback=1) + def test_removing_ticker_using_store_key_in_attribute(self): + """ + Test adding a ticker, storing the store_key in an attribute, and then removing it + using that same store_key. + + https://github.com/evennia/evennia/pull/3765 + """ + obj = DefaultObject.create("test_object")[0] + th = TickerHandler() + obj.db.ticker = th.add(60, obj.msg, idstring="ticker_test", persistent=True) + self.assertTrue(len(th.all()), 1) + th.remove(store_key=obj.db.ticker) + self.assertTrue(len(th.all()), 0) + class TestScriptDBManager(TestCase): """Test the ScriptDBManger class""" diff --git a/evennia/scripts/tickerhandler.py b/evennia/scripts/tickerhandler.py index 37853b592a..4848fe8a49 100644 --- a/evennia/scripts/tickerhandler.py +++ b/evennia/scripts/tickerhandler.py @@ -69,13 +69,12 @@ call the handler's `save()` and `restore()` methods when the server reboots. import inspect from django.core.exceptions import ObjectDoesNotExist -from twisted.internet.defer import inlineCallbacks - from evennia.scripts.scripts import ExtendedLoopingCall from evennia.server.models import ServerConfig from evennia.utils import inherits_from, variable_from_module from evennia.utils.dbserialize import dbserialize, dbunserialize, pack_dbobj from evennia.utils.logger import log_err, log_trace +from twisted.internet.defer import inlineCallbacks _GA = object.__getattribute__ _SA = object.__setattr__ @@ -566,8 +565,12 @@ class TickerHandler(object): store_key = self._store_key(obj, path, interval, callfunc, idstring, persistent) else: if isinstance(store_key, tuple) and not isinstance(store_key[0], tuple): + # this means the store-key was deserialized, which means we need to + # re-build the key anew (since the obj would already be unpacked otherwise) obj, path, callfunc = self._get_callback(getattr(store_key[0], store_key[1])) - store_key = self._store_key(obj, path, store_key[3], callfunc, store_key[4], store_key[5]) + store_key = self._store_key( + obj, path, store_key[3], callfunc, store_key[4], store_key[5] + ) to_remove = self.ticker_storage.pop(store_key, None) if to_remove: self.ticker_pool.remove(store_key)