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

Fix handling of multiple items (pinned recordings) having same mbid/msid #1831

Merged
merged 4 commits into from Feb 1, 2022

Conversation

amCap1712
Copy link
Member

It is possible to that multiple items have same msid/mbid. for example, pinning the same recording twice. Since the dict is keyed by mbid/msid the corresponding value should be a iterable of all items having that mbid so that such items are handled. Added test for the same.

@pep8speaks
Copy link

pep8speaks commented Jan 27, 2022

Hello @amCap1712! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 144:1: W391 blank line at end of file

Comment last updated at 2022-02-01 15:29:54 UTC

@@ -79,47 +80,49 @@ def fetch_track_metadata_for_items(items: List[ModelT]) -> List[ModelT]:
Returns:
The given list of MsidMbidModel objects with updated track_metadata.
"""
msid_item_map, mbid_item_map = {}, {}
# it is possible to that multiple items have same msid/mbid. for example, pinning the
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a bit unclear. Need to remove a stray "to"?

"artist_name": metadata["payload"]["artist"],
"additional_info": {
"recording_msid": msid
for item in msid_item_map[msid]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I iterate one item via another, I always consider what happens if it gets out of sync for some reason - e.g. what if msid_item_map[msid] doesn't exist? One solution would be to use for item in msd_item_map.get(msid, [])

That being said, I see that similar code has been in use before this, so probably not a great issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing is deleted from MsB ever so don't think this should be an issue. Also, if this is missing we need to fix code elsewhere as well because other places in codebase assume presence of title, artist name.


mapping_mbid_metadata, mapping_msid_metadata = load_recordings_from_mapping(mbid_item_map.keys(), msid_item_map.keys())
_update_items_from_map(mbid_item_map, mapping_mbid_metadata)
_update_items_from_map(msid_item_map, mapping_msid_metadata)
return items


def _update_items_from_map(models: Dict[str, ModelT], metadatas: Dict) -> Dict[str, ModelT]:
for _id, item in models.items():
def _update_items_from_map(models: Dict[str, Iterable[ModelT]], metadatas: Dict):
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment saying that it updates models in place would be helpful

Comment on lines +119 to +126
"track_name": metadata["title"],
"artist_name": metadata["artist"],
"release_name": metadata["release"],
"additional_info": {
"recording_msid": metadata["recording_msid"],
"recording_mbid": metadata["recording_mbid"],
"release_mbid": metadata["release_mbid"],
"artist_mbids": metadata["artist_mbids"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

not directly related to this PR, but are we always going to be sure that the metadata dict has all of these fields?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, these are the exact fields selected in load_recordings_from_mapping (above in this file) and this function is only called with data from that query.

@amCap1712 amCap1712 merged commit 155e269 into master Feb 1, 2022
@amCap1712 amCap1712 deleted the fix-dup-pins branch February 1, 2022 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants