Skip to content

Commit

Permalink
fix(command/inner/utils): calculate_update cannot handle empty entries
Browse files Browse the repository at this point in the history
A completely empty entry will make `calculate_update` use
`entry.content` as an alternative hash source. Though it is always a
list, it was mistakenly assumed to be a string, making such a fallback
causing AttributeError.

Fix it by extracting the first non-empty `content.value` in such a
circumstance.

Signed-off-by: Rongrong <[email protected]>
  • Loading branch information
Rongronggg9 committed May 11, 2024
1 parent ed59aaa commit f17326f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Bug fixes

- **Unable to handle completely empty posts**: Fix `AttributeError` caused by completely empty posts. They are ignored now.

## v2.7.0: #Hashtags from post, Python 3.12 support, and more

### BREAKING CHANGES
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.zh.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## 未发布

### Bug 修复

- **无法处理完全空白的文章**: 修复由完全空白的文章引起的 `AttributeError`。它们现在会被忽略。

## v2.7.0: 来自文章的 #hashtag、Python 3.12 支持和更多

### 重大变更
Expand Down
11 changes: 8 additions & 3 deletions src/command/inner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ def calculate_update(old_hashes: Optional[Sequence[str]], entries: Sequence[dict
for guid, entry in (
(
entry.get('guid') or entry.get('link') or entry.get('title') or entry.get('summary')
or entry.get('content', ''),
or (
# the first non-empty content.value
next(filter(None, map(lambda content: content.get('value'), entry.get('content', []))), '')
),
entry
) for entry in entries
) if guid
)
for entry in entries
)
if guid
}
if old_hashes:
new_hashes_d.update(zip(old_hashes, repeat(None)))
Expand Down

0 comments on commit f17326f

Please sign in to comment.