Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BadAttributeException when accessing repo.security_and_analysis.secret_scanning_ai_detection #3491

@adam-tapal

Description

@adam-tapal

class SecurityAndAnalysis(NonCompletableGithubObject):

There is a type mismatch in the SecurityAndAnalysis class mapping for the secret_scanning_ai_detection attribute. The class defines this attribute as expecting a string (Attribute[str]), but the GitHub REST API actually returns a nested dictionary object ({"status": "enabled"}). This causes a BadAttributeException whenever the property is read.

Environment
PyGitHub Version: 2.9.1
Python Version: 3.12

Steps to Reproduce

from github import Auth, Github
gh = Github(auth=Auth.Token(YOUR_TOKEN))
repo = gh.get_repo("your-org/your-repo")

# Triggers BadAttributeException
print(repo.security_and_analysis.secret_scanning_ai_detection)

Stack Trace / Error Log

File "site-packages\github\SecurityAndAnalysis.py", line 104, in secret_scanning_ai_detection
    return self._secret_scanning_ai_detection.value
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "site-packages\github\GithubObject.py", line 222, in value
    raise BadAttributeException(self.__value, self.__expectedType, self.__exception)
github.GithubException.BadAttributeException: ({'status': 'enabled'}, <class 'str'>, None)

Root Cause Analysis
In SecurityAndAnalysis.py, the attribute initialization is defined as:

self._secret_scanning_ai_detection: Attribute[str] = NotSet

However, the payload received from GitHub is actually:

"secret_scanning_ai_detection": {
    "status": "enabled"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions