Skip to content

Fix nil-pointer dereference in NewFilterResourceModel when API returns nil CaseSensitive#653

Open
see-cool wants to merge 3 commits into
OpsLevel:mainfrom
see-cool:fix/filter-nil-deref-case-sensitive
Open

Fix nil-pointer dereference in NewFilterResourceModel when API returns nil CaseSensitive#653
see-cool wants to merge 3 commits into
OpsLevel:mainfrom
see-cool:fix/filter-nil-deref-case-sensitive

Conversation

@see-cool

@see-cool see-cool commented Jun 10, 2026

Copy link
Copy Markdown

Resolves #

Problem

terraform plan panics with a nil-pointer dereference reading any opslevel_filter whose state holds a case_sensitive value for a predicate that the API returns as nil.

This blocks all filter operations on workspaces upgrading from older provider versions (0.8.x), since the old schema stored case_sensitive on every predicate regardless of whether the predicate type uses it.

Solution

Add a guard against dereferencing. opslevelPredicate.CaseSensitive != nil should be enough. When the API returns nil, it'll ultimately set the model field to BoolNull()) which represents that the value is unset.

The first commit adds a test that will fail when run, demonstrating the latent bug.

In a second commit, we introduce the patch that will fix the code and make the test pass. In addition to writing these test cases, I have used the patched code locally on my machine to run a terraform plan and it indeed succeeds after patching.

Checklist

  • I have run this code, and it appears to resolve the stated issue.
  • This PR does not reduce total test coverage
  • This PR has no user interface changes or has already received approval from product management to change the interface.
  • Make a changie entry that explains the customer facing outcome of this change

see-cool added 2 commits June 10, 2026 13:24
…s nil CaseSensitive

`terraform plan` panics with a nil-pointer dereference reading any
`opslevel_filter` whose state holds a case_sensitive value for a
predicate that the API returns as nil.

This blocks all filter operations on workspaces upgrading from older
provider versions (0.8.x), since the old schema stored case_sensitive on
every predicate regardless of whether the predicate type uses it.

This commit adds a test that will fail when run. In a second PR, I will
then introduce the patch that will cause the test to pass. In addition
to writing these test cases, I have used the patched  code locally on my
machine to run a `terraform plan` and it indeed succeeds after patching.
@see-cool see-cool marked this pull request as ready for review June 10, 2026 19:39
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 this pull request may close these issues.

2 participants