Skip to content

fix: detect empty cards when template uses special field conditionals#4807

Open
marcusl07 wants to merge 3 commits into
ankitects:mainfrom
marcusl07:main
Open

fix: detect empty cards when template uses special field conditionals#4807
marcusl07 wants to merge 3 commits into
ankitects:mainfrom
marcusl07:main

Conversation

@marcusl07
Copy link
Copy Markdown

@marcusl07 marcusl07 commented May 10, 2026

Linked issue (required)

Fixes #4750

Summary / motivation (required)

new_cards_required_normal() builds a set of non-empty fields from the note's actual fields, but only special-cases Tags. Other special fields like Deck, Subdeck, Card, CardFlag, Type, and CardID are always populated at render time but were missing from this set. This caused {{^Deck}} conditionals to be incorrectly evaluated as potentially rendering, making cards appear non-empty to the checker. The fix adds all always-present special fields to nonempty_fields.

Steps to reproduce (required)

  1. Create a Basic (and reversed card) note with content in both fields
  2. Change Card 1's front template to {{^Deck}}{{Back}}{{/Deck}}
  3. Observe the previewer shows a blank card
  4. Run Tools → Check → Empty Cards — no empty cards are reported

How to test (required)

Run ./ninja check:pytest — a new regression test test_empty_cards_special_fields in pylib/tests/test_cards.py covers this case.

Checklist (minimum)

  • I ran ./ninja check or an equivalent relevant check locally.
  • I added or updated tests when the change is non-trivial or behavior changed.

Details

New test verifies that a card with {{^Deck}}{{Back}}{{/Deck}} as its front template is correctly detected as empty.

Before / after behavior (optional)

Before: cards using special field conditionals like {{^Deck}} were not detected as empty. After: they are correctly flagged.

Risk / compatibility / migration (optional)

Low risk. Only affects empty card detection logic, not card rendering or scheduling.

UI evidence (required for visual changes; otherwise N/A)

N/A

Scope

  • This PR is focused on one change (no unrelated edits).

@marcusl07 marcusl07 changed the title git add CONTRIBUTORS git commit -m "add myself to contributors" git push fork main fix: detect empty cards when template uses special field conditionals May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anki does not detect empty cards with {{^Deck}}{{/Deck}}

1 participant