Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List.ElementsAs crashes #528

Closed
sebhoss opened this issue Nov 1, 2022 · 3 comments
Closed

List.ElementsAs crashes #528

sebhoss opened this issue Nov 1, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@sebhoss
Copy link

sebhoss commented Nov 1, 2022

Module version

github.com/hashicorp/terraform-plugin-framework v0.15.0

Relevant provider source code

import (
	"context"
	"github.com/hashicorp/terraform-plugin-framework/attr"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestListValue(t *testing.T) {
	values := []attr.Value{types.StringValue("refs/heads/main")}
	value, diags := types.ListValue(types.StringType, values)
	var refSpecs []string
	diags.Append(value.ElementsAs(context.TODO(), &refSpecs, false)...)
	assert.False(t, diags.HasError())
}

Terraform Configuration Files

Not related to Terraform configuration

Debug Output

https://gist.github.com/sebhoss/9c6f99a1a6014f2807c0b6589dc61de8

Expected Behavior

The above code should do a roundtrip from Go string to attr.Value and back to string.

Actual Behavior

Framework panics as seen in the log output. I can fix that on my end by switching from types.ListValue to types.ListValueFrom like this:

func TestListValue(t *testing.T) {
	values := []attr.Value{types.StringValue("refs/heads/main")}
	value, diags := types.ListValueFrom(context.TODO(), types.StringType, values)
	var refSpecs []string
	diags.Append(value.ElementsAs(context.TODO(), &refSpecs, false)...)
	assert.False(t, diags.HasError())
}

Steps to Reproduce

  1. Copy the above code snippet into project
  2. Run test

References

I have not found any related tickets.

@sebhoss sebhoss added the bug Something isn't working label Nov 1, 2022
@bflad bflad added this to the v0.16.0 milestone Nov 1, 2022
@bflad
Copy link
Member

bflad commented Nov 1, 2022

Hi @sebhoss 👋 Thank you for reporting this and sorry you ran into trouble here.

I believe this should already be fixed on main per #523 and will release with version 0.16.0 (along with those breaking changes).

@sebhoss
Copy link
Author

sebhoss commented Nov 1, 2022

Yep you are right - I tested against current main and the test passes just fine. Thanks for the quick reply!

@sebhoss sebhoss closed this as completed Nov 1, 2022
@github-actions
Copy link

github-actions bot commented Dec 2, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants