def remove_at(self, index=None):
        """
        Removes an item from the playlist. The playlist is a linked list, so
        this method takes care of removing the element and updating any links
        to it.
        """

        try:
            index = int(index)
        except:
            raise ValueError

        if index < 0:
            raise ValueError

        query = TrackPlaylistRelationship.query.filter_by(playlist=self)
        count = query.count()
        if index >= count:
            raise IndexError

        # Playlist-track relationship
        r_track = self.get_track_at(index)
        next_track = TrackPlaylistRelationship.query.filter(
            TrackPlaylistRelationship.playlist == self,
            TrackPlaylistRelationship.previous_track == r_track).first()

        if next_track:
            # Update linked list
            next_track.previous_track = r_track.previous_track
            db.session.add(next_track)

        # import ipdb; ipdb.set_trace()
        db.session.delete(r_track)
        db.session.commit()
dataset/ETHPy150Open tooxie/shiva-server/shiva/models.py/Playlist.remove_at/original