-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
tag.Add: allows users to register custom or missing tags into the tags registry #342
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @flicaflow! Couple thoughts:
- Can you add a couple sanity tests along with this? e.g. register a new tag and then check that you can successfully find it via one of the tag package APIs? (maybe in tag_test.go).
- How should we handle cases where a tag a user is trying to add already exists in the underlying dict? Should we return an error unless the user also sets an
overrideExisting = true
or something?
Otherwise, having a feature like this sounds good to me! :)
Hi @suyashkumar ,
Thanks for you reply, the unit test follows soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
I as a user of the API would expect that Registering a tag will just do that and eventually overriding an existing one. Maybe that is even desired because you need to give it another VR type. Having this not as the default is dangerous because maybe with an update the list of pre-defined tags gets extended and suddenly my code breaks. Users can easily add a check to see if a tag already exists if desired. If we want to have this feature in it I would vote for a second function like RegisterCustomIfNotExist(...)
Interesting, I was somewhat worried about someone unknowingly updating a tag value that might be used or important in other places. This could also silently break or change logic the user may not expect or know how to debug. Plus, I suppose updating the library can always come with new errors returned that may not have previously, so what you say is always a possibility. I tend to want to err on the side of extra safety, particularly since tags are not updated often (and plus, it'd notify you that you could maybe remove your custom code), but I see your point. I wonder if we should rename the function. RegisterCustom
makes it seem like it's for adding new "custom" tags vs. overriding existing ground truth data. WDYT about tag.SetInfo(tag.Info{})
? The use of the Set
verb makes it more implicitly clear that existing data may be changing, and of course we can continue to make that clear in the description. We can also include a note that you can check for existing tags before calling SetInfo if you want to ensure existing tags are not updated.
If we're worried about the override behavior, we could also throw a force
boolean parameter into the function so the user has to be more explicit about this. Do you have a few other examples of when you'd be overriding existing tag info intentionally?
Other than that, overall lgtm with the minor changes suggested below.
WDYT?
pkg/tag/tag_test.go
Outdated
if info.VR != "UT" || | ||
info.Name != "TestTag" || | ||
info.VM != "1" { | ||
t.Fatal("info of new registered tag is wrong") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you should be able to use cmp.Diff
to check the info exactly matches the struct you created above: https://pkg.go.dev/github.com/google/go-cmp/cmp#Diff
You could optionally check that both FindByName and Find returns the correct struct.
pkg/tag/tag_test.go
Outdated
if info.VR != "UT" || | ||
info.Name != "TestTag" || | ||
info.VM != "1" { | ||
t.Fatal("info of new registered tag is wrong") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: prefer t.Errorf
here and above to collect all test errors. Typically I use t.Errorf for test failure conditions, and Fatalf for test setup issues where the test needs to stop immediately.
I absolutely agree with naming it err := tag.Add(newTag, false) // errors if the tag already exists
err = tag.Add(newTag, true) // overwrites an eventually existing tag and never returns an error |
change comment wording of RegisterCustom function Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Makes sense, and I think that sounds good to me. |
I completed the changes. Let me know what you think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you for the contribution!!! Just had a bunch of small style/opinion nitpicks that I added suggestions for (nothing major).
added stylistic improvements Co-authored-by: Suyash Kumar <suyashkumar2003@gmail.com>
Thank you, I applied stylistic changes. I was thinking about defining an Error and didn't do it because I didn't see other examples in the package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with one minor typo. I'm not sure that I can commit to this branch otherwise I'd have sent the fix myself!
Oh, jk, looks like it allowed me to add a commit! |
Merged 🎉 ! Thank you for the contribution @flicaflow :). |
From the discussion of the unmerged and probably obsolete PR #271 the idea was to Just a RegisterCustom function to the tag package. This PR is exactly that. I needed the TrackingID and TrackingUID tags which are currently not available. Following code enables me to use them now: