coderedcorp / coderedcorp/coderedcms

[BUG] Incorrect methodology for `is_menu_item_dropdown` simple tag

Aperta
#184 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Area: Core ⚙ Type: Tech Debt
Lingua principale
Python
Stelle
765
Fork
154
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

**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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Search the repository for the is_menu_item_dropdown simple tag and inspect how its page value is used. Reproduce the case where page is absent or defaults incorrectly, then verify the tag avoids calling page methods on a non-page value while preserving sub-link and child-link behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
django, python
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.