From 89be7c0c8d4d606518d97731ecc1137255004eb6 Mon Sep 17 00:00:00 2001 From: lemon24 Date: Mon, 11 Oct 2021 19:41:52 +0300 Subject: [PATCH] Fix entry_dedupe bug causing the flag of the newest entry to be set to False, even if it was true before. Found during to #140. Likely introduced in #254. --- CHANGES.rst | 13 +++++++++++ src/reader/plugins/entry_dedupe.py | 5 +++-- tests/test_plugins_entry_dedupe.py | 36 +++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 88d262ef..8a11fdcf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,19 @@ Unreleased * Support Python 3.10. (:issue:`248`) +* .. _yanked 2.2: + + Fix :mod:`~reader.plugins.entry_dedupe` bug introduced in 2.2, + causing the newest read entry to be marked as unread + if none of its duplicates are read (idem for important). + This was an issue *only when re-running the plugin for existing entries*, + not for new entries (since new entries are unread and unimportant). + To ensure people don't use the buggy version, + *reader* 2.2 was `yanked`_ from PyPI. + + +.. _yanked: https://pypi.org/help/#yanked + Version 2.2 ----------- diff --git a/src/reader/plugins/entry_dedupe.py b/src/reader/plugins/entry_dedupe.py index de552ca4..a602efce 100644 --- a/src/reader/plugins/entry_dedupe.py +++ b/src/reader/plugins/entry_dedupe.py @@ -348,12 +348,13 @@ def by_title(e): def _get_flag_args(entry, duplicates, name): - flag = any(getattr(d, name) for d in duplicates) + entries = duplicates + [entry] + flag = any(getattr(d, name) for d in entries) modified_name = f'{name}_modified' modifieds = ( getattr(e, modified_name) - for e in duplicates + [entry] + for e in entries if getattr(e, name) == flag and getattr(e, modified_name) ) modified = next(iter(sorted(modifieds)), None) diff --git a/tests/test_plugins_entry_dedupe.py b/tests/test_plugins_entry_dedupe.py index d2b7df08..40542c28 100644 --- a/tests/test_plugins_entry_dedupe.py +++ b/tests/test_plugins_entry_dedupe.py @@ -348,7 +348,7 @@ def test_plugin_once(make_reader, db_path, monkeypatch, tags): (9, False, None), ], ), - # read, no modified + # old read, no modified ( [ (1, True, None), @@ -358,6 +358,16 @@ def test_plugin_once(make_reader, db_path, monkeypatch, tags): (9, True, None), ], ), + # new read, no modified + ( + [ + (1, False, None), + (9, True, None), + ], + [ + (9, True, None), + ], + ), # all read, earliest modified of the read entries is used (last has modified) ( [ @@ -409,7 +419,7 @@ def test_read_modified_copying(make_reader, db_path, data, expected, same_last_u (9, False, None), ], ), - # important, no modified + # old important, no modified ( [ (1, True, None), @@ -419,6 +429,16 @@ def test_read_modified_copying(make_reader, db_path, data, expected, same_last_u (9, True, None), ], ), + # new important, no modified + ( + [ + (1, False, None), + (9, True, None), + ], + [ + (9, True, None), + ], + ), # none important, modified ( [ @@ -449,7 +469,7 @@ def test_read_modified_copying(make_reader, db_path, data, expected, same_last_u (9, False, datetime(2010, 1, 1)), ], ), - # important, modified + # old important, modified ( [ (1, True, datetime(2010, 1, 1)), @@ -459,6 +479,16 @@ def test_read_modified_copying(make_reader, db_path, data, expected, same_last_u (9, True, datetime(2010, 1, 1)), ], ), + # new important, old modified + ( + [ + (1, False, datetime(2010, 1, 1)), + (9, True, None), + ], + [ + (9, True, None), + ], + ), ]