You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your code snippet should say library.removeLabel(['Example'])
I am calling episode.removeLabel(['Example']) because that is the same API call made in the past (before swapping to batch edits), and that works for me (and all but this one user). Does calling this method on the library only remove the label from the batched episode? If I should be calling that on the library, perhaps that's the issue? I couldn't find much information on using these batched operations in the docs.
This appears to be a problem with that user's own Plex Media Server database. They should check for database corruption and optimize their database.
I am inclined to agree with you there. I've reviewed the API calls made to Plex and have not seen any issues (although the exact format of label removal is a bit convoluted), and obviously have not had issues with anyone else. I'll make that suggestion.
Oh I should add that in this case the episode labels show as removed within the API (e.g. printing the labels after the fact shows no removed label), but the XML of the episode itself shows the "removed" label still present.
library.removeLabel(['Example']) edits the batched items passed into batchMultiEdits().
episode.removeLabel(['Example']) is just editing the one episode. You're not doing any of the batching.
For example, this doesn't make sense.
library.batchMultiEdits([episode1, episode2, episode3, episode4])
episode1.removeLabel('Example')
library.saveMultiEdits() # What happened to episode2, episode3, and episode4?
Makes sense - I was assuming it was modifying the methods for the batched objects in some way so that the API calls were only submitted after the saveMultiEdits() call - but it does seem more clear that it's a library-level operation.
If it's in the XML data then it should be parsed into PlexAPI. I can't see any way it can show up in the XML but not parsed. I checked the episode I edited on my server and there is no label in the XML data.
That was my understanding/observation as well. I'll follow up with the user and suggest the DB corruption / optimization. Thanks!
I've noticed that this results in the Another Label being added, but remove_menot being removed, which seems like unintended behavior (and was actually the root cause of the prior issue). I understand it is counterintuitive to add a label to episode in this way (not via batch edits).
I tested your code snippet and it works as expected if I run the code to the end. The episode had Another Label and did not have remove_me.
I did find a small quirk if you stop before the saveMultiEdits(). The episode.removeLabel(['remove_me']) actually doesn't run because the library has multi-edit enabled. This is unexpected to me and is counter to what I said in my previous comment. I expected the episode to have no labels at this point.
What I expected:
plex=PlexServer('URL', 'TOKEN')
episode=plex.fetchItem(13312)
episode.addLabel('remove_me') # `remove_me` label addedlibrary=plex.library.section('LIBRARY NAME')
library.batchMultiEdits([episode])
episode.removeLabel(['remove_me']) # `remove_me` label removedlibrary.addLabel(['Another Label']) # `Another Label` waiting for saving multi-edits to add# episode has no labelslibrary.saveMultiEdits()
# episode only has `Another Label`
What actually happened:
plex=PlexServer('URL', 'TOKEN')
episode=plex.fetchItem(13312)
episode.addLabel('remove_me') # `remove_me` label addedlibrary=plex.library.section('LIBRARY NAME')
library.batchMultiEdits([episode])
episode.removeLabel(['remove_me']) # `remove_me` label waiting for saving multi-edits to removelibrary.addLabel(['Another Label']) # `Another Label` waiting for saving multi-edits to add# episode has `remove_me` labellibrary.saveMultiEdits()
# episode only has `Another Label`
In this scenario on my and three other users' PCs, the multi edit label (remove_me) is not removed, and the episode label (add_me) is added. Are you able to replicate this?
Okay, I can reproduce the issue with that order of operations. I think the problem is the add function appends based on the current list of tags.
I don't know if this requires a fix, but I might have an idea. Or just don't use individual episode operations inside multi-edit per my original comment.
Note: this will fix the behaviour of doing episode.addLabel() inside a multi-edit to only change the one episode. i.e. What I expected to happen per my previous comment. So if you are using multi-edit, you must use library.addLabel().
That's great news, glad it's an easy fix/change. After that fix I'll also start properly using the multi edits, and that should be this issue resolved. Thanks
Activity
JonnyWong16 commentedon Oct 29, 2024
Your code snippet should say
library.removeLabel(['Example']).I also cannot reproduce the issue.
This appears to be a problem with that user's own Plex Media Server database. They should check for database corruption and optimize their database.
CollinHeist commentedon Oct 29, 2024
@JonnyWong16 Thanks for the quick response.
I am calling
episode.removeLabel(['Example'])because that is the same API call made in the past (before swapping to batch edits), and that works for me (and all but this one user). Does calling this method on the library only remove the label from the batched episode? If I should be calling that on the library, perhaps that's the issue? I couldn't find much information on using these batched operations in the docs.I am inclined to agree with you there. I've reviewed the API calls made to Plex and have not seen any issues (although the exact format of label removal is a bit convoluted), and obviously have not had issues with anyone else. I'll make that suggestion.
CollinHeist commentedon Oct 29, 2024
Oh I should add that in this case the episode labels show as removed within the API (e.g. printing the labels after the fact shows no removed label), but the XML of the episode itself shows the "removed" label still present.
JonnyWong16 commentedon Oct 29, 2024
library.removeLabel(['Example'])edits the batched items passed intobatchMultiEdits().episode.removeLabel(['Example'])is just editing the one episode. You're not doing any of the batching.For example, this doesn't make sense.
There's an example in the documentation:
https://python-plexapi.readthedocs.io/en/latest/modules/library.html#plexapi.library.LibrarySection.batchMultiEdits
If it's in the XML data then it should be parsed into PlexAPI. I can't see any way it can show up in the XML but not parsed.
I checked the episode I edited on my server and there is no label in the XML data.
CollinHeist commentedon Oct 29, 2024
Makes sense - I was assuming it was modifying the methods for the batched objects in some way so that the API calls were only submitted after the
saveMultiEdits()call - but it does seem more clear that it's a library-level operation.That was my understanding/observation as well. I'll follow up with the user and suggest the DB corruption / optimization. Thanks!
CollinHeist commentedon Nov 6, 2024
@JonnyWong16 Hey, sorry for the ping, would you be able to comment on the expected behavior here?
I've noticed that this results in the
Another Labelbeing added, butremove_menot being removed, which seems like unintended behavior (and was actually the root cause of the prior issue). I understand it is counterintuitive to add a label toepisodein this way (not via batch edits).JonnyWong16 commentedon Nov 6, 2024
I tested your code snippet and it works as expected if I run the code to the end. The episode had
Another Labeland did not haveremove_me.I did find a small quirk if you stop before the
saveMultiEdits(). Theepisode.removeLabel(['remove_me'])actually doesn't run because the library has multi-edit enabled. This is unexpected to me and is counter to what I said in my previous comment. I expected the episode to have no labels at this point.What I expected:
What actually happened:
CollinHeist commentedon Nov 6, 2024
There must be a difference in behavior when doing add/remove operations, I had mixed up the two for my example - can you run:
In this scenario on my and three other users' PCs, the multi edit label (
remove_me) is not removed, and the episode label (add_me) is added. Are you able to replicate this?JonnyWong16 commentedon Nov 6, 2024
Okay, I can reproduce the issue with that order of operations. I think the problem is the add function appends based on the current list of tags.
I don't know if this requires a fix, but I might have an idea. Or just don't use individual episode operations inside multi-edit per my original comment.
JonnyWong16 commentedon Nov 6, 2024
The fix is actually really easy. Just need to change this one line.
https://github.com/pkkid/python-plexapi/blob/aba6b9862fa8898bf24da55e1fc859548a9bcbf6/plexapi/library.py#L1743
Note: this will fix the behaviour of doing
episode.addLabel()inside a multi-edit to only change the one episode. i.e. What I expected to happen per my previous comment. So if you are using multi-edit, you must uselibrary.addLabel().Fix editing single objects when batchMultiEdit() is enabled
CollinHeist commentedon Nov 6, 2024
That's great news, glad it's an easy fix/change. After that fix I'll also start properly using the multi edits, and that should be this issue resolved. Thanks
Fix editing single objects when batchMultiEdit() is enabled (#1479)