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

AttributeError: 'NoneType' object has no attribute 'is_using_auth_credentials' #502

Open
pawamoy opened this issue Jan 31, 2024 · 1 comment · May be fixed by #519
Open

AttributeError: 'NoneType' object has no attribute 'is_using_auth_credentials' #502

pawamoy opened this issue Jan 31, 2024 · 1 comment · May be fixed by #519

Comments

@pawamoy
Copy link

pawamoy commented Jan 31, 2024

  • safety version: 3.0.1
  • Python version: 3.11
  • Operating System: Linux

Description

I'm using safety programmatically:

from safety.formatter import SafetyFormatter
from safety.safety import calculate_remediations, check
from safety.util import read_requirements

if isinstance(requirements, (list, tuple, set)):
    requirements = "\n".join(requirements)
packages = list(read_requirements(StringIO(cast(str, requirements))))
vulns, db_full = check(packages=packages, ignore_vulns=ignore_vulns)

It fails with the following traceback:

Traceback (most recent call last):
File "/media/data/dev/duty/src/duty/callables/safety.py", line 54, in check
  vulns, db_full = check(packages=packages, ignore_vulns=ignore_vulns)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/media/data/dev/duty/__pypackages__/3.11/lib/safety/util.py", line 743, in new_func
  return f(*args, **kwargs)
         ^^^^^^^^^^^^^^^^^^
File "/media/data/dev/duty/__pypackages__/3.11/lib/safety/safety.py", line 374, in check
  db = fetch_database(session, db=db_mirror, cached=cached, telemetry=telemetry)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/media/data/dev/duty/__pypackages__/3.11/lib/safety/safety.py", line 222, in fetch_database
  if session.is_using_auth_credentials():
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'is_using_auth_credentials'

The check method has a default value of None for the session parameter, but that default value causes the fetch_database function to raise an AttributeError since it doesn't check if it's None before trying to access is_using_auth_credentials on it.

Previously, on v2, the above code worked. I understand that I can expect breaking changes going from v2 to v3, but maybe this particular issue was an oversight and can be solved on your side. Let me know! I can also fix my own code to instantiate a session myself and provide it to the check function. By the way what is the type of this session object?

@pawamoy
Copy link
Author

pawamoy commented Jan 31, 2024

I was able to fix it on my end with this:

from safety.auth.cli_utils import build_client_session

client_session, _ = build_client_session()
vulns, db_full = check(session=client_session, packages=packages, ignore_vulns=ignore_vulns)

Entanglement with Click did not make this easy to find 😓

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 a pull request may close this issue.

1 participant