Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError when accessing deck configuration in Anki 24+ #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kaderator2
Copy link

Fixed a bug where the add-on would crash with a KeyError: 'conf' when trying to create new deadlines. This occurred because recent versions of Anki (24+) changed how deck configurations are stored and accessed.

Changes made:

  1. Updated deck configuration access from by_name(deck)['conf'] to use the new API
  2. Now uses deck_obj.get("conf_id", 1) instead of accessing 'conf' directly

This fix maintains all existing functionality while making it compatible with current Anki versions. Tested working on Anki 24.11.

Related error:

Traceback (most recent call last):
  File "/home/chade/.local/share/Anki2/addons21/723639202/config.py", line 89, in readValues
    self.applyDeadlineForDeck(deck,date)
  File "/home/chade/.local/share/Anki2/addons21/723639202/config.py", line 105, in applyDeadlineForDeck
    if (mw.col.decks.by_name(deck)['conf'] == 1):
        ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'conf'

Fixed a bug where the add-on would crash with a KeyError: 'conf' when trying to create new deadlines. This occurred because recent versions of Anki (24+) changed how deck configurations are stored and accessed.
Changes made:
1. Updated deck configuration access from by_name(deck)['conf'] to use the new API
2. Now uses deck_obj.get("conf_id", 1) instead of accessing 'conf' directly
3. Properly retrieves and creates deck configurations using current Anki methods:
get_config() to access current configuration
add_config_returning_id() to create new configurations
Saves deck changes using proper deck object updates



This fix maintains all existing functionality while making it compatible with current Anki versions. Tested working on Anki 24.11.
Fix deck configuration updates for Anki 24+

Changes made:
- Updated deck configuration handling to work with newer Anki API (24+)
- Fixed new cards per day override by using the correct "newLimit" property
- Fixed review limit override using "reviewLimit" property
- Removed outdated configuration methods
- No longer creates duplicate deck presets

The addon now properly:
1. Sets deck-specific overrides for both new cards per day and maximum reviews
2. Sets maximum reviews to 10x the new cards per day limit
3. Preserves existing deck configurations instead of creating new ones
4. Works with the current Anki API structure

This fixes the issue where deck configuration changes weren't being applied in Anki 24+.
@kaderator2
Copy link
Author

Fix deck configuration updates for Anki 24+

Changes made:

  • Updated deck configuration handling to work with newer Anki API (24+)
  • Fixed new cards per day override by using the correct "newLimit" property
  • Fixed review limit override using "reviewLimit" property
  • Removed outdated configuration methods
  • No longer creates duplicate deck presets

The addon now properly:

  1. Sets deck-specific overrides for both new cards per day and maximum reviews
  2. Sets maximum reviews to 10x the new cards per day limit
  3. Preserves existing deck configurations instead of creating new ones
  4. Works with the current Anki API structure

This fixes the issue where deck configuration changes weren't being applied in Anki 24+.

Fix conf error
@BSCrumpton
Copy link
Owner

@kaderator2 I'll try and give this a test later this week. If all works well, I'll go ahead and merge it in! If you end up wanting to do future enhancements, happy to ether give you contributor role or let you take over the project.

@BSCrumpton
Copy link
Owner

BSCrumpton commented Dec 23, 2024

alrighty, so something currently isn't right with refreshing the UI after deleting a deadline- the "New" doesn't change correctly. I'll take a look slightly deeper into that (at least confirmed a problem on ⁨23.12.1. If it's fine on newest 24 then we wont' worry about it) Edit- as an update, if you hit the process deadlines button, it updates the UI

There's also a problem with the "New cards seen today:" Field, but that was an issue before this version of the addon. Will need to see if I can fix that while feeling froggy

Looks like we're still creating the new deck config, we're not applying it to the deck afterwards.
Additionally, after deleting a deadline, the new config isn't getting correctly removed.

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.

2 participants