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

Writing to collection destroys tags #50

Open
exc4l opened this issue Nov 29, 2020 · 14 comments
Open

Writing to collection destroys tags #50

exc4l opened this issue Nov 29, 2020 · 14 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@exc4l
Copy link
Contributor

exc4l commented Nov 29, 2020

MWE:

col = Collection(user='testing')
notes = col.notes
selection = notes[notes.has_tag("leech")]
#selection = selection.add_tag(["marked"])
col.notes.update(selection)
col.write(modify=True)

col.summarize_changes() for this:

======== notes ========
Total rows: 10347
Compared to original version:
Modified rows: 0
Added rows: 0
Deleted rows: 0

This doesn't result in an immediate error but after opening anki the card browser is unable to find notes/cards by tag.

In the testing profile, I do have 32 notes tagged with 'leech'.
After writing when searching by the leech tag it shows no notes.
The notes are still there and if I search for them manually I can see that they indeed do have the leech tag.
If I, after now manually selecting them, do a search again for the leech tag, they do appear but also only the ones I selected manually.

When using the .add_tag() function the new tags do show up in the notes but it's the same with the leech tag. The card browser is only able to find the new tag after I manually selected the cards.

This isn't fixed by anki's "check database" function.

As mentioned before I'm using an older anki version. If you aren't able to reproduce this let me know and I will see that I try the same with the newest anki version.

Furthermore, as you might see I'm doing the selection a bit different than your example in the readme. This example:

selection = col.notes.has_tags(["Japanese", "leech"])
selection = selection.add_tag(["difficult-japanese", "marked"])
col.notes.update(selection)
col.write(modify=True)  # Overwrites your database after creating a backup!

results in:

----> 2 selection = selection.add_tag(["difficult-japanese", "marked"])

~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5137             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5138                 return self[name]
-> 5139             return object.__getattribute__(self, name)
   5140 
   5141     def __setattr__(self, name: str, value) -> None:

AttributeError: 'Series' object has no attribute 'add_tag'

Could the first part be relating to #32 ? In my case no duplicates seem to be created though.

@klieret klieret added the bug Something isn't working label Nov 30, 2020
@klieret klieret self-assigned this Nov 30, 2020
@klieret
Copy link
Owner

klieret commented Nov 30, 2020

Right, the example definitely is just wrong, thanks for reporting this!

@klieret
Copy link
Owner

klieret commented Nov 30, 2020

Yes, as for the tags, this is something I also spotted yesterday. I have already added a quick warning message when writing out that tags will probably have hickups.

I'm not yet sure how to fix this though. I don't understand the database in this respect yet.

@exc4l
Copy link
Contributor Author

exc4l commented Nov 30, 2020

I see. Due to the wording or maybe my misinterpretation, I thought it meant problems regarding syncing with the anki-server and not that anki will be unable to find the tagged cards.

WARNING: Currently AnkiPandas might not be able to tell Anki to sync its tags. So if you added any new tags, you might have to manually tell Anki to sync everything if you want to see and use them in AnkiDroid.

@klieret
Copy link
Owner

klieret commented Nov 30, 2020

True, I also didn't expect that there would also be issues with even finding the cards... (or that even existing tags can't be found). This is quite bad indeed.

@klieret
Copy link
Owner

klieret commented Nov 30, 2020

Though I have to say that I'm still surprised that this should affect existing tags. Because basically we don't even touch the part of the database which might contain some information about the tags, but really only write out the notes table if this is the one that was modified.

@klieret
Copy link
Owner

klieret commented Dec 6, 2020

I can confirm that this is happening. :/

@klieret klieret changed the title Writing to the collection (col.write(modify=true)) breaks the collection Writing to collection destroys tags Dec 6, 2020
@klieret
Copy link
Owner

klieret commented Dec 6, 2020

Hi @exc4l

I'm currently not sure if I can fix this properly, as writing info metadata (tags) and the like to anki doesn't work and I don't know how to fix this.

However, here is a workaround: If you first select "Notes > Clear unused notes" and then "Tools > Check Database", it seems to work for me.

@klieret
Copy link
Owner

klieret commented Dec 6, 2020

Can you confirm if this is working?

@exc4l
Copy link
Contributor Author

exc4l commented Dec 6, 2020

Doesn't work for me.
Used the exact code from the mwe.
Started Anki up after execution, card browser only showed the leech tag -> 0 notes when selected
Notes -> clear unused tags -> now marked and leech show up in the browser but no notes if searched for them.
After checking the database it's still the same.

Is your message wrong or do you actually mean clear unused notes instead of tags?

@klieret
Copy link
Owner

klieret commented Dec 6, 2020

No, for me it worked as I described above. Hmm :/

@klieret
Copy link
Owner

klieret commented Dec 6, 2020

This will probably require more reverse engineering about how to access anki's "tags" SQL table. Unfortunately, it's using something called "unicase" in this table yet which I have yet to somehow include in order to even open the table....

@klieret
Copy link
Owner

klieret commented Dec 6, 2020

Perhaps we should look for someone who's working on ankidroid or similar projects to help out here..

@exc4l
Copy link
Contributor Author

exc4l commented Dec 6, 2020

I can confirm that this wokaround is working for anki 2.1.35

Guess something changed with the newer versions and it didn't work on my main due to me using an older anki version.

@klieret
Copy link
Owner

klieret commented Dec 6, 2020

Oh, I'm relieved! Still, I hope we can figure out how to do this properly in the long run....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants