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

[BUG]: SAST Projects causing InvalidFieldValue error when getting all projects for an org #162

Open
1 task done
brian-hamill-bv opened this issue Dec 5, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@brian-hamill-bv
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

When using the Snyk client to get an individual org, then get all projects for that org an error is returned. This error seems to be because the SAST/Code Analysis projects return null/None for the totalDependencies value.

Steps To Reproduce

Create a python script with the following code and run it against any org that includes projects of type SAST/Code Analysis.

import snyk
client = snyk.SnykClient('api-key-here', tries=5, debug=True)
print(client.organizations.get('org-id-here').projects.all())

Additional Information

The full error messages (with file paths and org IDs removed) is as follows:

DEBUG:snyk.client:GET: https://snyk.io/api/v1/orgs
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): snyk.io:443
DEBUG:urllib3.connectionpool:https://snyk.io:443 "GET /api/v1/orgs HTTP/1.1" 200 2050
DEBUG:snyk.client:GET: https://snyk.io/api/v1/org/org-id-here/projects
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): snyk.io:443
DEBUG:urllib3.connectionpool:https://snyk.io:443 "GET /api/v1/org/org-id-here/projects HTTP/1.1" 200 1665
Traceback (most recent call last):
  File "<string>", line 78, in from_dict
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/path-here/script.py", line 7, in <module>
    print(client.organizations.get('org-id-here').projects.all())
  File "/path-here/Library/Python/3.9/lib/python/site-packages/snyk/managers.py", line 172, in all
    return self._query()
  File "/path-here/Library/Python/3.9/lib/python/site-packages/snyk/managers.py", line 163, in _query
    projects.append(self.klass.from_dict(project_data))
  File "<string>", line 85, in from_dict
mashumaro.exceptions.InvalidFieldValue: Field "totalDependencies" of type int in Project has invalid value None
@brian-hamill-bv brian-hamill-bv added the bug Something isn't working label Dec 5, 2022
@Fatal1ty
Copy link

Fatal1ty commented Dec 5, 2022

I believe this is related to the version 3.2 of mashumaro that fixed no error when passing None values to fields that shouldn't be None.

if None value is ok for totalDependencies then this field should be annotated as Optional[int] to fix this issue.

@Gil-Tohar-Forter
Copy link

I am running into this issue a well, i think TotalDependencies needs to be annotated as mentioned above!

@sndrsnk
Copy link

sndrsnk commented Jan 16, 2023

We're also experiencing this issue.

@ndoell
Copy link

ndoell commented Mar 2, 2023

Same issue here. I seem to be seeing this error pop up when pysnyk runs into an IaC project while using client.organizations.get(org_id).projects.get(p.id).issueset_aggregated.all()

@ig596
Copy link
Contributor

ig596 commented Sep 7, 2023

I believe I corrected this in #169. If so, please mark this as closed/resolved.

@kbroughton
Copy link

@ig596 I just tried with version 0.9.18 and still get the same error using the simple test at the top of the issue

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

No branches or pull requests

7 participants