Anki generates cards with too long CIDs

So, I have digged deeper into this.
Something seems to be messed up in my Anki collection. I could not reproduce the behaviour on a new Anki profile though. The error occurs randomly, I haven’t found a way to reproduce reliably other than mass generating cards and checking through the info.

It would really help if there was a pointer on what could produce this error, so I could help with finding reliable reproduction steps. I’m willing to do more experiments, but I would like a more systematic approach.

Also, I might be in need of finding a way to fix my SQL database properly this time, including the revlog.

Reproduction steps

1. Loading into my profile, all add-ons disabled
2. Create new deck "test"
3. Select a cloze note type, and with Remembering field content enabled, mass create a lot of cloze cards
4. some of the cards will have too long CIDs, generating very strange "Added" information
5. Note that this also affects cards other than of the cloze notetype, this is just a quick way of generating cards.

Anki debug information

Anki 2.1.36 (53a984ba) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Mac 10.15.7
Flags: frz=True ao=False sv=2
Add-ons, last update check: 2020-11-05 11:10:06


===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])


===IDs of active AnkiWeb add-ons===

I’m able to reproduce the error with the aforementioned reproduction steps even on fresh profiles on Anki 2.1.35 if I import a deck with “malicious” IDs earlier.

Test deck to import before following the reproduction steps:

Anki debug info:

Anki 2.1.36 (53a984ba) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Mac 10.15.7
Flags: frz=True ao=False sv=1
Add-ons, last update check: 2020-11-05 11:10:06


===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])


===IDs of active AnkiWeb add-ons===

When adding cards rapidly, Anki will use largest id+1 in the event of a conflict, so this issue is caused by already having large ids in your collection.

You will need to open your collection in a program like ‘sqlitebrowser’ then run the following sql commands:

create table fix (new_id integer not null primary key, old_id int);
insert into fix (old_id) select id from cards where id > 2000000000000;
update fix set new_id = new_id + 1604610984297;
update cards set id = (select new_id from fix where old_id = id) where id > 2000000000000;
delete from revlog where cid > 2000000000000 and cid not in (select old_id from fix);
update revlog set cid = (select new_id from fix where old_id = cid) where cid > 2000000000000;
drop table fix;

Remember to backup first, and force a full sync afterwards. Please let the deck author/tool know of the issue.

1 Like

Thanks a lot, this worked like a charm!
The source of the deck is already informed, although I might send another mail that fixing this issue is of utmost importance.