Files
anki/pylib/tests
Marcus Lo 3186cc31c4 fix: detect empty cards when template uses special field conditionals (#4807)
## 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)
- [x] I ran `./ninja check` or an equivalent relevant check locally.
- [x] 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
- [x] This PR is focused on one change (no unrelated edits).
2026-07-06 01:44:19 +08:00
..
2022-11-27 15:24:20 +10:00
2021-06-27 15:12:22 +10:00
2021-10-25 14:50:13 +10:00
2024-02-28 16:28:04 +07:00
2025-06-29 14:38:35 +07:00
2021-06-27 12:12:23 +10:00