Skip to content

Fix nil-pointer panic when deleting github_team_repository - #3518

Merged
stevehipwell merged 2 commits into
integrations:mainfrom
rilical:fix-team-repository-nil-response-panic
Jul 6, 2026
Merged

stevehipwell merged 2 commits into
integrations:mainfrom
rilical:fix-team-repository-nil-response-panic

Conversation

@rilical

@rilical rilical commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Resolves #3517


Before the change?

resourceGithubTeamRepositoryDelete read resp.StatusCode without checking whether resp was nil. When Teams.RemoveTeamRepoByID fails at the transport layer (for example a cancelled context or an exceeded deadline), google/go-github returns a nil *github.Response (in bareDo, a transport error yields (nil, err)), so the delete panicked with a nil-pointer dereference instead of returning the error:

panic: runtime error: invalid memory address or nil pointer dereference
    github/resource_github_team_repository.go:226

In a terraform apply/destroy, a transient network error while removing a team's repository access could crash the provider. This is the only unguarded resp.StatusCode dereference in the github/ package; the other call sites already use resp != nil && resp.StatusCode.

After the change?

  • Guard the status check with resp != nil, matching the pattern already used elsewhere in the provider. When resp is nil, the underlying error now flows through handleArchivedRepoDelete and is returned as a diagnostic instead of panicking.
  • Add a regression test (Test_resourceGithubTeamRepositoryDelete_nilResponseDoesNotPanic) that drives delete with a cancelled context so the API call returns a nil response, asserting delete returns an error diagnostic. It panics at line 226 without the fix and passes with it.

Verification:

  • go test ./github/ -run '^Test_resourceGithubTeamRepositoryDelete_nilResponseDoesNotPanic$' panics before the change, passes after.
  • Full unit suite green (make test, which skips ^TestAcc).
  • Happy path unchanged against a live org: TestAccGithubTeamRepository passes (create / read / import / update / destroy).

Pull request checklist

  • Schema migrations have been created if needed — N/A, no schema change
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed — N/A, no user-facing schema or behavior change beyond not panicking

Does this introduce a breaking change?

  • Yes
  • No

AI-assisted disclosure: this change was developed with AI assistance (GitHub Copilot). Per the repository's AI Use Policy I have reviewed and understand the change, verified the root cause in google/go-github's bareDo (nil *Response on transport error), and tested it with a deterministic unit regression test plus a live acceptance run of TestAccGithubTeamRepository.

resourceGithubTeamRepositoryDelete read resp.StatusCode without checking
whether resp was nil. When RemoveTeamRepoByID fails at the transport
layer (for example a cancelled context or an exceeded deadline),
go-github returns a nil *github.Response, so delete panicked instead of
returning the error. This can crash terraform apply/destroy on a
transient network error during team-repository removal.

Guard the check with resp != nil, matching the pattern already used
elsewhere in the provider. When resp is nil the underlying error now
flows through handleArchivedRepoDelete and is returned as a diagnostic.

Add a regression test that drives delete with a cancelled context so the
API call returns a nil response, asserting delete returns an error
diagnostic instead of panicking.

Co-authored-by: Copilot App <[email protected]>
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

👋 Hi, and thank you for this contribution!

This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions.


🤖 This is an automated message.

@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label Jul 2, 2026
robert-crandall
robert-crandall previously approved these changes Jul 2, 2026

@robert-crandall robert-crandall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this - really thorough writeup and root-cause analysis. I confirmed the fix and the regression test locally: it panics on the old code and passes with the guard, exactly as described. Nice deterministic repro using a cancelled context. 🙌

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @rilical, just a minor change required. Did you happen to search for other cases where this pattern hasn't been implemented correctly?

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @rilical.

FYI for context; the error handling in this function isn't correctly implemented and there also appears to be unnecessary complexity. This whole block needs updating to check for an error and then use errors.AsType to check for a GitHub error with a response.

@stevehipwell stevehipwell added this to the v6.13.0 milestone Jul 3, 2026
@stevehipwell
stevehipwell merged commit f3c63cb into integrations:main Jul 6, 2026
11 checks passed
corymhall pushed a commit to pulumi/pulumi-github that referenced this pull request Aug 14, 2026
Unblocks the nightly `upgrade-provider` job and pulls in upstream
v6.13.0.

## Why this was stuck

Upstream v6.13.0 refactored the provider entry point in
[#3440](integrations/terraform-provider-github#3440),
replacing the parameterless `github.Provider()` with
`github.NewProvider(version, commit)`, which returns the provider
factory.

The nightly [Upgrade
provider](https://github.com/pulumi/pulumi-github/actions/workflows/upgrade-provider.yml)
job rebases onto the new tag fine, then dies in codegen:

```
./scripts/upstream.sh rebase -o refs/tags/v6.13.0: done
error: upgrade-provider executed `make tfgen` which failed: exit status 2:
./resources.go:78:33: undefined: github.Provider
make: *** [Makefile:323: bin/pulumi-tfgen-github] Error 1
```

It has failed every night since v6.13.0 was released on 2026-07-08, so
the bridge is still pinned to upstream v6.12.1 and none of the fixes
below have shipped.

## Changes

- `provider/resources.go`: use `github.NewProvider(version.Version,
"")()`. `version` and `commit` only feed the upstream User-Agent and
debug logging; the bridge appends its own Pulumi User-Agent, so the
commit is left empty. This is the only hand-written change.
- `upstream`: v6.12.1 → v6.13.0 (via `upstream.sh checkout` / `rebase -o
refs/tags/v6.13.0` / `check_in`).
- Regenerated schema, all five SDKs, and `docs/_index.md`.

## Notable upstream fixes pulled in

- **`github_team_repository` delete now treats a 404 from GitHub as a
successful delete**
([#3524](integrations/terraform-provider-github#3524)).
Previously the 404 branch only recovered from repository *renames*: it
re-read the repo and retried the delete only when `.GetName()` differed.
A repository transferred to a **different organization** keeps its name,
so the retry was skipped and the original 404 surfaced as a hard error.
Any stack still holding that resource in state is then permanently
wedged — every subsequent update fails on the same undeletable resource,
and the only escape is `pulumi state delete`.
- Fixes a nil-pointer panic in that same delete path when the API call
fails at the transport layer
([#3518](integrations/terraform-provider-github#3518)).
- `github_team_members` deletion is skipped when the parent team is
already gone
([#3461](integrations/terraform-provider-github#3461)).

## Schema impact

Additive — nothing removed or retyped (verified by diffing schema keys
against `master`):

- New provider config options: `cachePath`, `legacyClient`
- New resource properties: `BranchDefault.repositoryId`,
`BranchDefault.waitForRename`,
`RepositoryCollaborators.ownerConfigured`,
`RepositoryCustomProperty.repositoryId`, `TeamMembers.teamSlug`

The bulk of the schema and `docs/_index.md` diff is upstream's migration
to tfplugindocs
([#3380](integrations/terraform-provider-github#3380))
and its rewritten provider docs and examples
([#3440](integrations/terraform-provider-github#3440))
— restyled descriptions, and the overview example changing from
`github_membership` to `getRepository` because upstream replaced
`examples/provider/example_1.tf`/`example_2.tf` with a single
`provider.tf`.

## Verification

- `make tfgen` succeeds; example conversion 93.39% (1314/1407)
- All five SDKs generated; Go SDK compiles
- `dotnet build` not run locally (unrelated local NuGet source
misconfiguration) — leaving that to CI
- Acceptance tests not run locally

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: nil-pointer panic deleting github_team_repository when the delete API call returns a nil response

4 participants