Skip to content

404 and other errors when calling delete() method on Github.Secret.Secret and GitHub.Variable.Variable #2834

@AndrewJDawes

Description

@AndrewJDawes

Methods called on Secret and Variable model methods are not requesting the correct GitHub REST API endpoint URLs. Invoking these methods causes 404 errors.

  • For Variable, there is a bug that appends additional incorrect parts to the variable's REST API endpoint URL, resulting in 404 errors for delete (HTTP DELETE) and edit (HTTP PATCH).
    • Example:
      • Expected: /repos/{owner}/{repo}/actions/variables/{name}
      • Actual: /repos/{owner}/{repo}/actions/variables/{name}/actions/variables/{name}
  • For both Variable and Secret, fetching a PaginatedList of either from the Repository model's get_variables or get_secrets methods fails to correctly set the _url attribute on the paginated list of models. Therefore, calling such methods will also fail.

Below are some examples for how to reproduce the unexpected behavior. Please substitute "AndrewJDawes/PyGithub" with the owner/name of a repository to which you have access.

# Setup
repo = self.g.get_repo("AndrewJDawes/PyGithub")
variable = repo.create_variable("VARIABLE_NAME", "VARIABLE_VALUE")
repo = self.g.get_repo("AndrewJDawes/PyGithub")
variable = repo.get_variable("VARIABLE_NAME")


# Issue
variable.delete() # github.GithubException.UnknownObjectException: 404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest"}
repo = self.g.get_repo("AndrewJDawes/PyGithub")
repo.create_variable("VARIABLE_ONE_NAME", "VARIABLE_ONE_VALUE")
repo.create_variable("VARIABLE_TWO_NAME", "VARIABLE_TWO_VALUE")
repo = self.g.get_repo("AndrewJDawes/PyGithub")
variables = repo.get_variables()
for variable in variables:
    if variable.name in ["VARIABLE_ONE_NAME", "VARIABLE_TWO_NAME"] and variable.value in ["VARIABLE_ONE_VALUE", "VARIABLE_TWO_VALUE"]:
        variable.delete() # Fails to delete Variable
  repo = self.g.get_repo("AndrewJDawes/PyGithub")
  repo.create_secret("SECRET_ONE_NAME", "SECRET_ONE_VALUE")
  repo.create_secret("SECRET_TWO_NAME", "SECRET_TWO_VALUE")
  repo = self.g.get_repo("AndrewJDawes/PyGithub")
  secrets = repo.get_secrets()
  for secret in secrets:
      if secret.name in ["SECRET_ONE_NAME", "SECRET_TWO_NAME"]:
          secret.delete() # AttributeError: 'NoneType' object has no attribute 'startswith'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions