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

feat(artifacts): add save() method on ArtifactCollection to allow persisting changes #7555

Conversation

amusipatla-wandb
Copy link
Contributor

@amusipatla-wandb amusipatla-wandb commented May 3, 2024

Description

This PR adds the setter functions for name, type, description, and tags in ArtifactCollection, and adds a save function to persist these changes.

Example usage:

collection = wandb.Api().artifact_collection("type-name", "collection_name")
collection.description = "new description"
collection.name = "new_name"
collection.type = "new_type"
collection.tags = ["tag"]
collection.save()
  • I updated CHANGELOG.md, or it's not applicable

Testing

Added integration tests

@amusipatla-wandb amusipatla-wandb changed the title feat(artifacts): add ability to edit and save properties of artifact collection feat(artifacts): add save() method on ArtifactCollection to allow persisting changes May 3, 2024
Copy link

codecov bot commented May 3, 2024

Codecov Report

Attention: Patch coverage is 98.14815% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 75.86%. Comparing base (fc7b2b5) to head (a128749).

Additional details and impacted files

Impacted file tree graph

@@                              Coverage Diff                               @@
##           amusipatla/artifact-collection-pull-fields    #7555      +/-   ##
==============================================================================
+ Coverage                                       75.82%   75.86%   +0.04%     
==============================================================================
  Files                                             500      500              
  Lines                                           54066    54119      +53     
==============================================================================
+ Hits                                            40993    41055      +62     
+ Misses                                          12665    12656       -9     
  Partials                                          408      408              
Flag Coverage Δ
func 41.45% <31.48%> (+0.02%) ⬆️
system 63.51% <98.14%> (+0.07%) ⬆️
unit 56.37% <31.48%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
wandb/apis/public/artifacts.py 92.94% <98.14%> (+1.82%) ⬆️

... and 7 files with indirect coverage changes

@amusipatla-wandb amusipatla-wandb marked this pull request as ready for review May 3, 2024 21:02
@amusipatla-wandb amusipatla-wandb requested review from a team as code owners May 3, 2024 21:02
CHANGELOG.md Outdated Show resolved Hide resolved
wandb/apis/public/artifacts.py Outdated Show resolved Hide resolved
wandb/apis/public/artifacts.py Outdated Show resolved Hide resolved
wandb/apis/public/artifacts.py Outdated Show resolved Hide resolved
wandb/apis/public/artifacts.py Outdated Show resolved Hide resolved
wandb/apis/public/artifacts.py Show resolved Hide resolved
wandb/apis/public/artifacts.py Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
wandb/apis/public/artifacts.py Outdated Show resolved Hide resolved
@amusipatla-wandb amusipatla-wandb force-pushed the amusipatla/artifact-collection-save branch from 71b993e to dc3cd1d Compare May 8, 2024 15:48
Copy link
Contributor

@ibindlish ibindlish left a comment

Choose a reason for hiding this comment

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

most of the tag-related changes lgtm. just a suggestion regarding the characters that aren't allowed.

wandb/apis/public/artifacts.py Outdated Show resolved Hide resolved
wandb/apis/public/artifacts.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ibindlish ibindlish left a comment

Choose a reason for hiding this comment

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

Approving mainly for the tags part. The rest lgtm too, but might want to check with @estellazx or @moredatarequired since they were involved in the api design. Great work! 😄

Copy link
Contributor

@moredatarequired moredatarequired left a comment

Choose a reason for hiding this comment

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

Thanks for adding the deprecation! LGTM

)
self._type = type

def save(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a mild preference for breaking this up somehow, probably by making smaller private functions for each of the GQL operations. It's up to you though, feel free to merge as-is

Copy link
Contributor

@tonyyli-wandb tonyyli-wandb left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! Only had one question (with a possible suggestion depending on the answer)

@property
def tags(self):
"""The tags associated with the artifact collection."""
return self._tags

@tags.setter
def tags(self, tags: List[str]) -> None:
if any(not re.match(r"^[-\w]+([ ]+[-\w]+)*$", tag) for tag in tags):
Copy link
Contributor

Choose a reason for hiding this comment

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

question: may have missed this, so looking to understand first -- is the tag allowed to start or end with a hyphen/underscore (e.g. "-this-is-my-tag_")? If yes, understood -- just wanted to check

Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion(if-minor): If no, I think the condition/regex may need to could be stricter here -- up to you -- since it'll consider the above example valid. Possible, rough suggestion below:

Suggested change
if any(not re.match(r"^[-\w]+([ ]+[-\w]+)*$", tag) for tag in tags):
if any(not _is_valid_tag(tag) for tag in tags):

where:

def _is_valid_tag(tag: str) -> bool:
    split_tag = re.split(r"[ ]+|[-]+|[_]+", tag)
    return all(part.isalnum() for part in split_tag)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, it looks like via the UI we're able to start or end tags with hyphens/underscores so I think what we have right now should be fine

@amusipatla-wandb amusipatla-wandb merged commit 249c2c5 into amusipatla/artifact-collection-pull-fields May 17, 2024
37 of 39 checks passed
@amusipatla-wandb amusipatla-wandb deleted the amusipatla/artifact-collection-save branch May 17, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants