Skip to content

Commit

Permalink
fix: skip_duplicate doesn't respect user_id
Browse files Browse the repository at this point in the history
  • Loading branch information
faradox committed Feb 25, 2024
1 parent 00b0072 commit a76b3bb
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/nendo/library/sqlalchemy_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _create_track_from_file(
# skip adding a duplicate based on config flag and hashsum of the file
skip_duplicate = skip_duplicate or self.config.skip_duplicate
if skip_duplicate:
tracks = list(self.find_tracks(value=file_checksum))
tracks = list(self.find_tracks(value=file_checksum, user_id=user_id))
if len(tracks) > 0:
return schema.NendoTrack.model_validate(tracks[0])

Expand Down Expand Up @@ -344,7 +344,7 @@ def _add_tracks_db(
file_paths: List[FilePath],
track_type: str = "track",
copy_to_library: Optional[bool] = None,
skip_duplicate: bool = True,
skip_duplicate: Optional[bool] = None,
user_id: Optional[uuid.UUID] = None,
meta: Optional[Dict[str, Any]] = None,
) -> List[schema.NendoTrack]:
Expand Down Expand Up @@ -626,11 +626,12 @@ def _upsert_track_db(
Returns:
model.NendoTrackDB: The ORM model object of the upserted track
"""
track_dict = track.model_dump()
track_dict.pop("nendo_instance")
new_track = model.NendoTrackDB(**track_dict)
if type(track) == schema.NendoTrackCreate:
# create new track
track_dict = track.model_dump()
track_dict.pop("nendo_instance")
db_track = model.NendoTrackDB(**track_dict)
db_track = new_track
session.add(db_track)
else:
# update existing track
Expand All @@ -639,12 +640,12 @@ def _upsert_track_db(
)
if db_track is None:
raise schema.NendoTrackNotFoundError("Track not found", id=track.id)
db_track.user_id = track.user_id
db_track.visibility = track.visibility
db_track.resource = track.resource.model_dump()
db_track.track_type = track.track_type
db_track.images = track.images
db_track.meta = track.meta
db_track.user_id = new_track.user_id
db_track.visibility = new_track.visibility
db_track.resource = new_track.resource
db_track.track_type = new_track.track_type
db_track.images = new_track.images
db_track.meta = new_track.meta
session.commit()
return db_track

Expand Down

0 comments on commit a76b3bb

Please sign in to comment.