Fix database saves mutating site detectors (#3184)

Co-authored-by: Soxoj <soxoj@protonmail.com>
This commit is contained in:
Sushanth012
2026-10-10 23:38:41 +03:00
committed by GitHub
co-authored by Soxoj
parent bd21950f94
commit 9e70b591b0
2 changed files with 17 additions and 4 deletions
+4 -4
View File
@@ -357,10 +357,10 @@ class MaigretSite:
if not self.engine_obj:
return self
self.request_future = None
self.url_regexp = None
self_copy = copy.deepcopy(self)
self_copy = copy.copy(self)
self_copy.request_future = None
self_copy.url_regexp = None
self_copy = copy.deepcopy(self_copy)
engine_data = self_copy.engine_obj and self_copy.engine_obj.site or {}
site_data_keys = list(self_copy.__dict__.keys())
+13
View File
@@ -119,6 +119,19 @@ def test_site_strip_engine_data():
assert amperka_stripped.json == EXAMPLE_DB['sites']['Amperka']
def test_saving_database_preserves_site_url_detector(tmp_path):
db = MaigretDatabase()
db.load_from_json(EXAMPLE_DB)
amperka = db.sites[0]
db.save_to_file(str(tmp_path / 'data.json'))
assert (
amperka.detect_username('http://forum.amperka.ru/members/?username=test')
== 'test'
)
def test_site_strip_engine_data_with_site_prior_updates():
db = MaigretDatabase()
UPDATED_EXAMPLE_DB = dict(EXAMPLE_DB)