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 partial filename from paths_prefix #591

Merged
merged 1 commit into from
Jul 25, 2022
Merged

Conversation

jjnesbitt
Copy link
Member

@jjnesbitt jjnesbitt commented Nov 5, 2021

I was using the asset paths code for OASIS project, and I noticed a bug: If you provide part of an asset's path in path_prefix, the resulting path in files will be the remainder, not the entire filename, as you'd expect.

For example, given an asset with the name a/b/c.zip, providing a/b/c to path_prefix yields an entry in files with .zip.

This PR just fixes the name if it's a file. The behavior is still valid if it's a folder, so it doesn't touch that branch.

While that endpoint does have the following description

The specified path must be a folder; it either must end in a slash or
(to refer to the root folder) must be the empty string.

I don't see a reason not to handle this case 🤷‍♂️

@@ -440,6 +440,8 @@ def paths(self, request, versions__dandiset__pk: str, versions__version: str, **
is_folder = folder_index >= 0

if not is_folder:
# Ensure base_path is entire filename
base_path = asset.path[asset.path.rfind('/') + 1 :]
Copy link
Member

Choose a reason for hiding this comment

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

could you please add a unittest for this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Apologies for never providing an update: I attempted to add a quick test for this, but ran into logistical issues. Since at the time I wasn't active on this project, and this enhancement came from work on another repository, I had to abandon this to continue my other obligations. Maybe now that I'm back on the project I can finish this up.

Copy link
Member

Choose a reason for hiding this comment

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

Welcome back @AlmightyYakob !

Copy link
Member

Choose a reason for hiding this comment

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

@AlmightyYakob please update on adding a unittest -- this is the eldest (6 mo?) PR ATM. We better decide on its destiny asap

Copy link
Member

Choose a reason for hiding this comment

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

@AlmightyYakob ping on this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding a unit test here would be nice, but requires a refactor of our testing setup, and doesn't provide much value, so I'll just merge this.

waxlamp added a commit that referenced this pull request Jan 7, 2022
@jjnesbitt jjnesbitt merged commit 988a9b2 into master Jul 25, 2022
@jjnesbitt jjnesbitt deleted the fix-partial-asset-path branch July 25, 2022 15:02
@dandibot
Copy link
Member

🚀 PR was released in v0.2.40 🚀

@dandibot dandibot added the released This issue/pull request has been released. label Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants