coderedcorp / coderedcorp/coderedcms
[BUG] Incorrect methodology for `is_menu_item_dropdown` simple tag
- 主要言語
- Python
- スター
- 765
- フォーク
- 154
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
**Describe the bug**
A clear and concise description of what the bug is.
This code block:
@register.simple_tag
def is_menu_item_dropdown(value):
return \
len(value.get('sub_links', [])) > 0 or \
(
value.get('show_child_links', False) and \
len(value.get('page', []).get_children().live()) > 0
)
What if you actually hit the case where `value.get('page', [])` defaults to a list? Then `.get_children().live()` is being called on an object which doesn't have these methods. Also, probably shouldn't inline all of this for readability despite the faster evaluation.
One simple fix:
@register.simple_tag
def is_menu_item_dropdown(value):
has_sub_links = len(value.get('sub_links', [])) > 0
show_child_links = value.get('show_child_links', False)
page_has_children = False
if has_sub_links or show_child_links: # No need to evaluate the below if this case fails...
page = value.get('page')
if page is not None:
page_has_children= len(page.get_children().live()) > 0
return has_sub_links or (show_child_links and page_has_children)
This is also assuming you still want to be verbose with the evaluation into booleans here.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
リポジトリで is_menu_item_dropdown simple tag を検索し、その page の値がどのように使われているかを調べます。page が存在しない場合やデフォルト値が誤っている場合を再現し、そのうえで、タグが page でない値に対して page のメソッドを呼び出さないことを確認するとともに、サブリンクと子リンクの動作が維持されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- django, python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100