PyGithub / PyGithub/PyGithub

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

Open
#2,834 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
1.9k
Avg merge
17m
Merged PRs (30d)
2

Description

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'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Secret and Variable model methods and the Repository.get_variables and get_secrets entry points. Reproduce the listed delete and edit failures, then compare the generated REST URLs and paginated model _url values with the expected endpoints. Done means these operations work for individual and paginated Secret and Variable objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.