Skip to content

Commit

Permalink
copy_entry() should also copy tags. #290
Browse files Browse the repository at this point in the history
  • Loading branch information
lemon24 committed Dec 5, 2024
1 parent 86ac646 commit b5e5e82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/reader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ def copy_entry(self, src: EntryInput, dst: EntryInput, /) -> None:
"""Copy an entry from one feed to another.
All :class:`Entry` attributes that belong to the entry are copied,
including timestamps like :attr:`~Entry.added`,
including timestamps like :attr:`~Entry.added`, entry tags,
and hidden attributes that affect behavior (e.g. sorting).
If the original does not already have a :attr:`~Entry.source`,
Expand Down Expand Up @@ -1654,6 +1654,8 @@ def copy_entry(self, src: EntryInput, dst: EntryInput, /) -> None:
# TODO: not atomic, maybe add to intent later on
self.set_entry_read(dst, src_entry.read, src_entry.read_modified)
self.set_entry_important(dst, src_entry.important, src_entry.important_modified)
for key, value in self.get_tags(src_entry):
self.set_tag(dst, key, value)

def enable_search(self) -> None:
"""Enable full-text search.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,8 @@ def test_copy_entry(reader, data_dir, data_file):
reader._now = lambda: datetime(2010, 1, 2)
reader.mark_entry_as_read(src_id)
reader.mark_entry_as_unimportant(src_id)
reader.set_tag(src_id, 'empty')
reader.set_tag(src_id, 'key', 'value')

reader._now = lambda: datetime(2010, 2, 1)
dst_url = 'dst'
Expand All @@ -2864,10 +2866,14 @@ def clean(entry):
feed=None,
)

def get_tags(entry):
return dict(reader.get_tags(entry))

src = reader.get_entry(src_id)
dst = reader.get_entry(dst_id)

assert clean(src) == clean(dst)
assert get_tags(src) == get_tags(dst)

assert dst.id == 'id'
assert dst.added_by == 'user'
Expand Down

0 comments on commit b5e5e82

Please sign in to comment.