cjcodeproj / medialibrary

Python code to read XML media files
MIT License
2 stars 0 forks source link

Repo content objects clobber each other #184

Closed cjcodeproj closed 3 months ago

cjcodeproj commented 3 months ago

The Repo code has a content array that looks like this.

https://github.com/cjcodeproj/medialibrary/blob/f37e074d29e6ecdb38942ca38e92663f5176b7df/src/media/fileops/repo.py#L46-L52

And it adds content to the contents array like this.

https://github.com/cjcodeproj/medialibrary/blob/f37e074d29e6ecdb38942ca38e92663f5176b7df/src/media/fileops/repo.py#L87-L91

But if two disparate pieces of content share the same title, then the second content object will go missing, even if that content object is a different class.

I noticed this when I tried to load both the movie "Moonraker" and the soundtrack "Moonraker".

cjcodeproj commented 3 months ago

Discovery

The problem lies with the equality test with the Movie class.

https://github.com/cjcodeproj/medialibrary/blob/f37e074d29e6ecdb38942ca38e92663f5176b7df/src/media/data/media/contents/movie/internal.py#L78-L81

It's comparing the unique_key values of both objects, which are probably identical. So, the clobbering is only taking place between two objects when one of them is a member of the Movie class.

cjcodeproj commented 3 months ago

Commit:

https://github.com/cjcodeproj/medialibrary/commit/b5b95e99055ef5a8429fabffd14f69d14beb6938

cjcodeproj commented 3 months ago

Closing Notes

The issue actually only was noticeable if one of the content objects was a Movie object, because the Movie class is the one that had the equality check operator.

The object still has __lt__ and __gt__ operators which will get removed soon.

See there related tickets:

https://github.com/cjcodeproj/medialibrary/issues/148 https://github.com/cjcodeproj/medialibrary/issues/172