Skip to content

Conversation

@7se7en72025
Copy link
Contributor

Purpose / Description

Migrate all usages of the deprecated notetypes.current() API to the recommended col.defaultsForAdding() API. The old API had inconsistent behavior and didn't properly respect user preferences for notetype selection.

Fixes

Approach

Replaced all 27+ occurrences of col.notetypes.current() throughout the codebase with col.notetypes.get(col.defaultsForAdding().notetypeId)!!. The new API provides more accurate defaults that respect:

  • Current review context (if in a review session)
  • User preference for whether defaults should follow current deck or notetype
  • The backend's recommended notetype for adding cards

Migration Pattern:

  • col.notetypes.current()col.notetypes.get(col.defaultsForAdding().notetypeId)!!
  • col.notetypes.current().didcol.defaultsForAdding().deckId

Files Modified (11 total):

  • Production code: NoteEditorFragment.kt, CardContentProvider.kt, DevOptionsFragment.kt
  • Test utilities: Collection.kt (testutils)
  • Test files: MediaTest.kt, CollectionTest.kt, FinderTest.kt, SchedulerTest.kt, CardTest.kt, ReviewerTest.kt, NoteTypeTest.kt

How Has This Been Tested?

Compilation & Lint:

  • ./gradlew compilePlayDebugKotlin - Successful
  • ./gradlew lintPlayDebug - No new issues
  • ./gradlew ktlintCheck - All style checks pass

Unit Tests:

  • ./gradlew :libanki:testDebugUnitTest - All migration-related tests pass
  • ✅ Fixed FinderTest.test_findCards to explicitly pass notetype when needed
  • Pre-existing test failures (AlarmManagerServiceTest, timing-related) are unrelated to this change

Test Environment:

  • Windows with PowerShell
  • JDK 21
  • Gradle 9.2.0

Learning (optional, can help others)

The deprecated notetypes.current() method had complex fallback logic that tried to determine the "current" notetype by checking:

  1. The deck's preferred notetype
  2. A global config value
  3. The first available notetype

The new defaultsForAdding() backend API is more robust because it:

  • Respects the user's preference setting (ADDING_DEFAULTS_TO_CURRENT_DECK)
  • Can consider the current review context (home deck of review card)
  • Returns both deck ID and notetype ID in a single call
  • Aligns with Anki Desktop's behavior

Reference: Anki Python implementation

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

No UI changes in this refactoring - purely internal API migration with no user-facing impact.

@david-allison
Copy link
Member

david-allison commented Dec 1, 2025

This change is much larger than expected.

Upstream only has one usage in production code:

https://github.com/search?q=repo%3Aankitects%2Fanki+defaults_For_Adding+language%3APython&type=code&l=Python

In addition: a large number of usages of this call are much more verbose. If we are going to use get(defaultsForAdding.ntid), then this should be a useful extension method on AnkiTest.kt

The libAnki code should match the upstream Python, could you get a reference to when the tests were removed/updated?

@7se7en72025
Copy link
Contributor Author

Python tests don’t use the verbose defaults_for_adding() pattern at all,use helpers like col.models.current(), col.newNote(), so there’s no upstream “removal” commit. I added Collection.defaultNotetype() ,replaced ~18 verbose call sites so tests follow that style, keeping defaultsForAdding() for production-only use

@david-allison
Copy link
Member

Could you link a free example sources? I must have missed them in my example scan

@7se7en72025
Copy link
Contributor Author

https://github.com/ankitects/anki/blob/main/pylib/tests/test_models.py
line 23,34,123,...
nt = col.models.get(col.defaults_for_adding()["ntid"])
this was the only place they use it in prod code

@david-allison
Copy link
Member

Ok, thanks

  • Add a val current on AnkiTest and use this, with the implementation delegating to the new functionality
  • @Deprecate fun current()

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Dec 4, 2025
@david-allison david-allison changed the title Deprecation/move to col libAnki: prefer defaultsForAdding Dec 4, 2025
@david-allison
Copy link
Member

Please focus on quality. This doesn't compile

  • Squash and force push your commits
  • Have a brief check that things look reasonable before submitting
  • Re-read your code before submitting, you've removed some methods and I don't understand why

@7se7en72025
Copy link
Contributor Author

7se7en72025 commented Dec 4, 2025

Please focus on quality. This doesn't compile

  • Squash and force push your commits
    yea sure i will
  • Have a brief check that things look reasonable before submitting
    i did but
  • Re-read your code before submitting, you've removed some methods and I don't understand why*<
    after i did commit, the checking process didnt start, it suggested some changes for conflict , i accepted incoming changes, it is failing checks .as shown below.
image

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hasn't gone through a self-review

Deprecates Notetypes.current() in favor of col.defaultsForAdding()

Fixes: 19650
Co-authored-by: David Allison <[email protected]>
@david-allison david-allison force-pushed the deprecation/move-to-col branch from 7b768ce to 8f8132e Compare December 5, 2025 03:11
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't take 5 days of back and forth. Please spend more time reading the code and the intention of my comments

I've rewritten and force pushed the following change

Subject: [PATCH] aa
---
Index: AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt
--- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/InstrumentedTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -32,6 +32,7 @@
 import com.ichi2.anki.libanki.CardType
 import com.ichi2.anki.libanki.Collection
 import com.ichi2.anki.libanki.Note
+import com.ichi2.anki.libanki.NotetypeJson
 import com.ichi2.anki.libanki.Notetypes
 import com.ichi2.anki.libanki.QueueType
 import com.ichi2.anki.testutil.addNote
@@ -216,6 +217,15 @@
 
     val notetypes get() = col.notetypes
 
+    /**
+     * Returns the current default notetype for adding new cards.
+     *
+     * @see Collection.defaultNotetype
+     */
+    @DuplicatedCode("From AnkiTest")
+    val Notetypes.current: NotetypeJson
+        get() = this.get(col.defaultsForAdding().notetypeId)!!
+
     val Notetypes.basic
         get() = byName("Basic")!!
 
Index: AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt
--- a/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/libanki/MediaTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -102,14 +102,12 @@
         val file = createNonEmptyFile("fake.png")
         testCol.media.addFile(file)
         // add a note which references it
-        @Suppress("DEPRECATION")
-        var f = testCol.newNote(testCol.notetypes.current())
+        var f = testCol.newNote(testCol.notetypes.current)
         f.setField(0, "one")
         f.setField(1, "<img src='fake.png'>")
         testCol.addNote(f)
         // and one which references a non-existent file
-        @Suppress("DEPRECATION")
-        f = testCol.newNote(testCol.notetypes.current())
+        f = testCol.newNote(testCol.notetypes.current)
         f.setField(0, "one")
         f.setField(1, "<img src='fake2.png'>")
         testCol.addNote(f)
Index: AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -2364,8 +2364,8 @@
             }
 
             if (!getColUnsafe.config.getBool(ConfigKey.Bool.ADDING_DEFAULTS_TO_CURRENT_DECK)) {
-                return getColUnsafe.defaultsForAdding().deckId.also {
-                    Timber.d("Adding to configured default deck: %d", it)
+                return getColUnsafe.defaultsForAdding().deckId.also { deckId ->
+                    Timber.d("Adding to configured default deck: %d", deckId)
                 }
             }
 
Index: AnkiDroid/src/main/java/com/ichi2/anki/preferences/DevOptionsFragment.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/DevOptionsFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/DevOptionsFragment.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/DevOptionsFragment.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/DevOptionsFragment.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -29,6 +29,7 @@
 import com.ichi2.anki.analytics.UsageAnalytics
 import com.ichi2.anki.dialogs.TtsVoicesDialogFragment
 import com.ichi2.anki.launchCatchingTask
+import com.ichi2.anki.libanki.Note
 import com.ichi2.anki.settings.Prefs
 import com.ichi2.anki.showThemedToast
 import com.ichi2.anki.snackbar.showSnackbar
@@ -234,9 +235,9 @@
                     }
                     withCol {
                         val deck = decks.addNormalDeckWithName(deckName(i))
-                        val notetypeId = defaultsForAdding().notetypeId
+                        val ntid = defaultsForAdding().notetypeId
                         addNote(
-                            newNote(notetypes.get(notetypeId)!!).apply { setField(0, "$i") },
+                            Note.fromNotetypeId(this, ntid).apply { setField(0, "$i") },
                             deck.id,
                         )
                     }
Index: AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/ReviewerTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -46,7 +46,6 @@
 import com.ichi2.anki.libanki.exception.ConfirmModSchemaException
 import com.ichi2.anki.libanki.testutils.ext.BASIC_NOTE_TYPE_NAME
 import com.ichi2.anki.libanki.testutils.ext.addNote
-import com.ichi2.anki.libanki.testutils.ext.defaultNotetype
 import com.ichi2.anki.libanki.testutils.ext.newNote
 import com.ichi2.anki.model.CardStateFilter
 import com.ichi2.anki.observability.undoableOp
@@ -456,7 +455,7 @@
     @Throws(ConfirmModSchemaException::class)
     @KotlinCleanup("use a assertNotNull which returns rather than !!")
     private fun addNoteWithThreeCards() {
-        var notetype = col.notetypes.copy(col.defaultNotetype())
+        var notetype = col.notetypes.copy(col.notetypes.current)
         notetype.name = "Three"
         col.notetypes.add(notetype)
         notetype = col.notetypes.byName("Three")!!
Index: AnkiDroid/src/test/java/com/ichi2/anki/libanki/NoteTypeTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/libanki/NoteTypeTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/libanki/NoteTypeTest.kt
--- a/AnkiDroid/src/test/java/com/ichi2/anki/libanki/NoteTypeTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/libanki/NoteTypeTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -22,7 +22,6 @@
 import com.ichi2.anki.libanki.exception.ConfirmModSchemaException
 import com.ichi2.anki.libanki.testutils.clozeClass
 import com.ichi2.anki.libanki.testutils.ext.addNote
-import com.ichi2.anki.libanki.testutils.ext.defaultNotetype
 import com.ichi2.anki.libanki.testutils.ext.newNote
 import com.ichi2.testutils.JvmTest
 import org.hamcrest.MatcherAssert.assertThat
@@ -40,7 +39,7 @@
     @Test
     fun test_frontSide_field() {
         // #8951 - Anki Special-cases {{FrontSide}} on the front to return empty string
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         noteType.templates[0].qfmt = "{{Front}}{{FrontSide}}"
         col.notetypes.save(noteType)
         val note = col.newNote()
@@ -63,7 +62,7 @@
     @Test
     fun test_field_named_frontSide() {
         // #8951 - A field named "FrontSide" is ignored - this matches Anki 2.1.34 (8af8f565)
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
 
         // Add a field called FrontSide and FrontSide2 (to ensure that fields are added correctly)
         col.notetypes.addFieldModChanged(noteType, col.notetypes.newField("FrontSide"))
@@ -96,13 +95,13 @@
         note.setItem("Back", "2")
         col.addNote(note)
         assertEquals(1, col.cardCount())
-        col.notetypes.remove(col.defaultNotetype().id)
+        col.notetypes.remove(col.notetypes.current.id)
         assertEquals(0, col.cardCount())
     }
 
     @Test
     fun test_modelCopy() {
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         val noteType2 = col.notetypes.copy(noteType)
         assertEquals("Basic copy", noteType2.name)
         assertNotEquals(noteType2.id, noteType.id)
@@ -121,7 +120,7 @@
         note.setItem("Front", "1")
         note.setItem("Back", "2")
         col.addNote(note)
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         // make sure renaming a field updates the templates
         col.notetypes.renameFieldLegacy(noteType, noteType.fields[0], "NewFront")
         assertThat(noteType.templates[0].qfmt, containsString("{{NewFront}}"))
@@ -229,7 +228,7 @@
     @Test
     @Throws(ConfirmModSchemaException::class)
     fun test_templates() {
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         var t =
             Notetypes.newTemplate("Reverse").apply {
                 qfmt = "{{Back}}"
@@ -284,7 +283,7 @@
     @Throws(ConfirmModSchemaException::class)
     fun test_cloze_ordinals() {
         col.notetypes.setCurrent(col.notetypes.byName("Cloze")!!)
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
 
         // We replace the default Cloze template
         val t =
@@ -313,7 +312,7 @@
     @Test
     fun test_text() {
         val noteType =
-            col.defaultNotetype().apply {
+            col.notetypes.current.apply {
                 templates[0].qfmt = "{{text:Front}}"
             }
         col.notetypes.save(noteType)
@@ -394,7 +393,7 @@
     @Suppress("SpellCheckingInspection") // chaine
     fun test_chained_mods() {
         col.notetypes.setCurrent(col.notetypes.byName("Cloze")!!)
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
 
         // We replace the default Cloze template
         val t =
@@ -428,7 +427,7 @@
     fun test_modelChange() {
         val cloze = col.notetypes.byName("Cloze")
         // enable second template and add a note
-        val basic = col.defaultNotetype()
+        val basic = col.notetypes.current
         val t =
             Notetypes.newTemplate("Reverse").apply {
                 qfmt = "{{Back}}"
@@ -556,7 +555,7 @@
 
     @Test
     fun test_updateNotetype_clears_cache() {
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         val originalName = noteType.name
         val noteTypeId = noteType.id
 
Index: libanki/src/main/java/com/ichi2/anki/libanki/Notetypes.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libanki/src/main/java/com/ichi2/anki/libanki/Notetypes.kt b/libanki/src/main/java/com/ichi2/anki/libanki/Notetypes.kt
--- a/libanki/src/main/java/com/ichi2/anki/libanki/Notetypes.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/libanki/src/main/java/com/ichi2/anki/libanki/Notetypes.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -32,6 +32,7 @@
 package com.ichi2.anki.libanki
 
 import androidx.annotation.CheckResult
+import androidx.annotation.VisibleForTesting
 import anki.collection.OpChanges
 import anki.collection.OpChangesWithId
 import anki.notetypes.ChangeNotetypeInfo
@@ -145,8 +146,8 @@
      */
 
     /** Get current model.*/
+    @VisibleForTesting
     @Deprecated("Use col.defaultsForAdding() instead")
-    @RustCleanup("Should use defaultsForAdding() instead")
     fun current(forDeck: Boolean = true): NotetypeJson {
         var noteType = get(col.decks.current().getLongOrNull("mid"))
         if (!forDeck || noteType == null) {
Index: libanki/src/test/java/com/ichi2/anki/libanki/CardTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libanki/src/test/java/com/ichi2/anki/libanki/CardTest.kt b/libanki/src/test/java/com/ichi2/anki/libanki/CardTest.kt
--- a/libanki/src/test/java/com/ichi2/anki/libanki/CardTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/libanki/src/test/java/com/ichi2/anki/libanki/CardTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -20,7 +20,6 @@
 import com.ichi2.anki.libanki.exception.ConfirmModSchemaException
 import com.ichi2.anki.libanki.testutils.InMemoryAnkiTest
 import com.ichi2.anki.libanki.testutils.ext.addNote
-import com.ichi2.anki.libanki.testutils.ext.defaultNotetype
 import com.ichi2.anki.libanki.testutils.ext.newNote
 import net.ankiweb.rsdroid.exceptions.BackendInvalidInputException
 import org.hamcrest.MatcherAssert.assertThat
@@ -74,7 +73,7 @@
         note.setItem("Back", "2")
         col.addNote(note)
         val c = note.cards()[0]
-        col.defaultNotetype().id
+        col.notetypes.current.id
         assertEquals(0, c.template().ord)
     }
 
@@ -85,7 +84,7 @@
         note.setItem("Back", "")
         col.addNote(note)
         assertEquals(1, note.numberOfCards())
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         // adding a new template should automatically create cards
         var t =
             Notetypes.newTemplate("rev").apply {
Index: libanki/src/test/java/com/ichi2/anki/libanki/CollectionTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libanki/src/test/java/com/ichi2/anki/libanki/CollectionTest.kt b/libanki/src/test/java/com/ichi2/anki/libanki/CollectionTest.kt
--- a/libanki/src/test/java/com/ichi2/anki/libanki/CollectionTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/libanki/src/test/java/com/ichi2/anki/libanki/CollectionTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -20,7 +20,6 @@
 import com.ichi2.anki.libanki.testutils.InMemoryAnkiTest
 import com.ichi2.anki.libanki.testutils.ext.addNote
 import com.ichi2.anki.libanki.testutils.ext.createBasicNoteType
-import com.ichi2.anki.libanki.testutils.ext.defaultNotetype
 import com.ichi2.anki.libanki.testutils.ext.newNote
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers
@@ -110,7 +109,7 @@
         var n = col.addNote(note)
         assertEquals(1, n)
         // test multiple cards - add another template
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         val t = Notetypes.newTemplate("Reverse")
         t.qfmt = "{{Back}}"
         t.afmt = "{{Front}}"
@@ -190,7 +189,7 @@
     @Test
     @Ignore("Pending port of media search from Rust code")
     fun test_furigana() {
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         // filter should work
         noteType.templates[0].qfmt = "{{kana:Front}}"
         col.notetypes.save(noteType)
Index: libanki/src/test/java/com/ichi2/anki/libanki/FinderTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libanki/src/test/java/com/ichi2/anki/libanki/FinderTest.kt b/libanki/src/test/java/com/ichi2/anki/libanki/FinderTest.kt
--- a/libanki/src/test/java/com/ichi2/anki/libanki/FinderTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/libanki/src/test/java/com/ichi2/anki/libanki/FinderTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -21,7 +21,6 @@
 import com.ichi2.anki.libanki.sched.Scheduler
 import com.ichi2.anki.libanki.testutils.InMemoryAnkiTest
 import com.ichi2.anki.libanki.testutils.ext.addNote
-import com.ichi2.anki.libanki.testutils.ext.defaultNotetype
 import com.ichi2.anki.libanki.testutils.ext.newNote
 import org.hamcrest.CoreMatchers.equalTo
 import org.hamcrest.MatcherAssert.assertThat
@@ -127,7 +126,7 @@
         note.setItem("Back", "sheep")
         col.addNote(note)
         val catCard = note.cards()[0]
-        var noteType = col.defaultNotetype()
+        var noteType = col.notetypes.current
         noteType = col.notetypes.copy(noteType)
         val t =
             Notetypes.newTemplate("Reverse").apply {
Index: libanki/src/test/java/com/ichi2/anki/libanki/SchedulerTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libanki/src/test/java/com/ichi2/anki/libanki/SchedulerTest.kt b/libanki/src/test/java/com/ichi2/anki/libanki/SchedulerTest.kt
--- a/libanki/src/test/java/com/ichi2/anki/libanki/SchedulerTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/libanki/src/test/java/com/ichi2/anki/libanki/SchedulerTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -30,7 +30,6 @@
 import com.ichi2.anki.libanki.sched.Counts
 import com.ichi2.anki.libanki.testutils.InMemoryAnkiTest
 import com.ichi2.anki.libanki.testutils.ext.addNote
-import com.ichi2.anki.libanki.testutils.ext.defaultNotetype
 import com.ichi2.anki.libanki.testutils.ext.newNote
 import org.hamcrest.CoreMatchers.equalTo
 import org.hamcrest.MatcherAssert
@@ -888,7 +887,7 @@
     @Throws(Exception::class)
     fun test_ordcycleV2() {
         // add two more templates and set second active
-        val noteType = col.defaultNotetype()
+        val noteType = col.notetypes.current
         var t =
             Notetypes.newTemplate("Reverse").apply {
                 qfmt = "{{Back}}"
Index: libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/AnkiTest.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/AnkiTest.kt b/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/AnkiTest.kt
--- a/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/AnkiTest.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/AnkiTest.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -340,25 +340,10 @@
     /**
      * Returns the current default notetype for adding new cards.
      *
-     * This property provides access to the default notetype based on
-     * the current deck and user preferences.
-     *
      * @see Collection.defaultNotetype
      */
-    val current: NotetypeJson
-        get() = col.defaultNotetype()
-
-    /**
-     * @deprecated Use the [current] property instead. This function is deprecated
-     * to align with the new API pattern of using a property for accessing
-     * the default notetype.
-     */
-    @Deprecated(
-        message = "Use 'current' property instead",
-        replaceWith = ReplaceWith("current"),
-        level = DeprecationLevel.WARNING,
-    )
-    fun current(): NotetypeJson = current
+    val Notetypes.current: NotetypeJson
+        get() = this.get(col.defaultsForAdding().notetypeId)!!
 
     val Notetypes.basic
         get() = byName("Basic")!!
Index: libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/ext/Collection.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/ext/Collection.kt b/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/ext/Collection.kt
--- a/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/ext/Collection.kt	(revision 7b768cef9be24e04c9908ad193f582f710fd848e)
+++ b/libanki/testutils/src/main/java/com/ichi2/anki/libanki/testutils/ext/Collection.kt	(revision d33729f4dc4625bc0f4d2cdcbefce0898561192d)
@@ -62,16 +62,6 @@
     return noteType
 }
 
-/**
- * Returns the default notetype for adding new cards.
- *
- * This is a convenience method for tests to avoid the verbose pattern:
- * `col.notetypes.get(col.defaultsForAdding().notetypeId)!!`
- *
- * Matches upstream Python: `col.models.get(col.defaults_for_adding()["ntid"])`
- */
-fun Collection.defaultNotetype(): NotetypeJson = notetypes.get(defaultsForAdding().notetypeId)!!
-
 /**
  * Return a new note with the model derived from the deck or the configuration
  * @param forDeck When true it uses the model specified in the deck (mid), otherwise it uses the model specified in

replaceWith = ReplaceWith("current"),
level = DeprecationLevel.WARNING,
)
fun current(): NotetypeJson = current
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it, this isn't what was asked for, and why add a deprecated method which is unused

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Author Reply Waiting for a reply from the original author labels Dec 5, 2025
@mikehardy mikehardy closed this Dec 7, 2025
@david-allison
Copy link
Member

I've force pushed this and feel it's ready for merge

@david-allison david-allison reopened this Dec 7, 2025
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed - looks clean and focused at this point, let's get it in

@mikehardy mikehardy added this pull request to the merge queue Dec 10, 2025
@mikehardy mikehardy added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Dec 10, 2025
Merged via the queue into ankidroid:main with commit 48482b3 Dec 10, 2025
32 checks passed
@github-actions github-actions bot added this to the 2.23 release milestone Dec 10, 2025
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Dec 10, 2025
@mikehardy mikehardy removed this from the 2.23 release milestone Dec 12, 2025
@mikehardy mikehardy added this to the 2.24 release milestone Dec 12, 2025
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.

deprecation(libanki): move to col.defaultsForAdding

3 participants