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

global incremental ID creates issues for consumers #166

Closed
alfredodeza opened this issue Sep 1, 2020 · 1 comment · Fixed by #329
Closed

global incremental ID creates issues for consumers #166

alfredodeza opened this issue Sep 1, 2020 · 1 comment · Fixed by #329
Labels
bug Something isn't working

Comments

@alfredodeza
Copy link
Contributor

What happened: The syft/pkg/catalog.go file has a global (unexported) variable that increments whenever a new package is added to the catalog. This creates a hard constraint of not being able to control the IDs and forces consumers to use the catalog one at the time.

This particular problem was evident when 2 tests where trying to create a pkg catalog from syft. When the two tests ran, one would fail. These tests were adding 3 packages each, and they both were relying on the fact that the IDs would be 0, 1, and 2. When both added the tests, the IDs for the second test would be 3, 4 and 5.

What you expected to happen: Not have a global auto-incrementing variable that is unexported, and possibly allow consumers to control it.

How to reproduce it (as minimally and precisely as possible): Create two functions that add to a pkg.catalog

Anything else we need to know?:

Environment:

  • syft version (use syft version -v):
  • OS (e.g: cat /etc/os-release or similar):
@alfredodeza alfredodeza added the bug Something isn't working label Sep 1, 2020
@wagoodman
Copy link
Contributor

Agreed on the global ID. Ultimately IDs should not have any expected behavior or pattern. We should probably change the ID to be a UUID to remove the statefulness of the existing IDs --allowing for consumer control would be a simple fix, but is not advised.

If the tests are within the the same package as the catalog, then setting them manually would be one approach. However, if tests reside outside of the package it would be difficult to redact these fields during comparison (hence, the problem you described).

Currently the ID field is used to distinguish when you have two package objects that are from the same catalog entry --this doesn't discount the possibility of having duplicate packages in the catalog (which is what #32 is meant to solve).

I think we should take time to solve the overall problem of the ID: what do we need it for? Can we solve the same problem without needing an ID field on the package which is assigned by the catalog?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants