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

[Bug]: Setting Column Default Crashes Snowflake Plugin #2997

Open
1 task
wpl-sf-nbirch opened this issue Aug 15, 2024 · 3 comments
Open
1 task

[Bug]: Setting Column Default Crashes Snowflake Plugin #2997

wpl-sf-nbirch opened this issue Aug 15, 2024 · 3 comments
Labels
bug Used to mark issues with provider's incorrect behavior resource:table Issue connected to the snowflake_table resource

Comments

@wpl-sf-nbirch
Copy link

wpl-sf-nbirch commented Aug 15, 2024

Terraform CLI Version

1.9.4

Terraform Provider Version

0.94.1

Terraform Configuration

Updated a table resource to set the DUPLICATE column to default constant = 0

resource "snowflake_table" "reporting_h" {
  database                    = var.snowflake_database
  schema                      = var.snowflake_schema
  name                        = local.report_h
  comment                     = "h reporting."
  cluster_by                  = []
  change_tracking             = false
  data_retention_time_in_days = 1

  column {
    name     = "KEY"
    type     = "VARCHAR(16777216)"
    nullable = false
  }

  column {
    name = "LOAD_TIMESTAMP"
    type = "TIMESTAMP_NTZ(9)"
  }

  column {
    name = "DUPLICATE"
    type = "NUMBER(38,0)"

    default {
      constant = 0
    }
  }
}

Category

category:resource

Object type(s)

No response

Expected Behavior

Table should be updated to have DUPLICATE column default to 0.

Actual Behavior

Get a plugin crash with the following errors:

Error: Plugin did not respond
The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.

Error: Request cancelled
The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.

Stack trace from the terraform-provider-snowflake_v0.94.1 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x15c152c]

goroutine 151 [running]:
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk.(*TableColumnActionRequest).toOpts(0xc000f0f1f0)
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/tables_impl.go:368 +0x56c
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk.(*AlterTableRequest).toOpts(0xc000a131d0)
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/tables_impl.go:128 +0x1a5
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk.(*tables).Alter(0xc0008584f8, {0x24b1240, 0x34cf420}, 0x1?)
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/tables_impl.go:59 +0x25
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources.UpdateTable(0xc0011cec00, {0x1cfa200?, 0xc00006caa0?})
github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/resources/table.go:817 +0x1f26
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x24b1278?, {0x24b1278?, 0xc0011df050?}, 0xd?, {0x1cfa200?, 0xc00006caa0?})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:800 +0x163
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000b3d260, {0x24b1278, 0xc0011df050}, 0xc00102bad0, 0xc0011cea80, {0x1cfa200, 0xc00006caa0})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:919 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00062aac8, {0x24b1278?, 0xc0011deea0?}, 0xc001189630)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:1078 +0xdbc
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ApplyResourceChange({{0x24c7fc0?, 0xc00062aac8?}}, {0x24b1278, 0xc0011deea0}, 0x0?)
github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf5to6server/tf5to6server.go:47 +0x54
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ApplyResourceChange(0x24b12b0?, {0x24b1278?, 0xc0011deba0?}, 0xc0011895e0)
github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf6muxserver/mux_server_ApplyResourceChange.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc0001ff680, {0x24b1278?, 0xc0011de390?}, 0xc00110a460)
github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/tf6server/server.go:846 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x20639e0?, 0xc0001ff680}, {0x24b1278, 0xc0011de390}, 0xc0011ce580, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.22.2/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0009dee00, {0x24b1278, 0xc0011de300}, {0x24c31e0, 0xc000016300}, 0xc0011a1e60, 0xc000bdc570, 0x348ad38, 0x0)
google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc0009dee00, {0x24c31e0, 0xc000016300}, 0xc0011a1e60)
google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 14
google.golang.org/grpc@v1.63.2/server.go:1030 +0x135

Error: The terraform-provider-snowflake_v0.94.1 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Steps to Reproduce

  1. Create a table resource without any column defaults
  2. Update the table resource with a column set to a default constant

How much impact is this issue causing?

Low

Logs

No response

Additional Information

Seems similar to 2406

Would you like to implement a fix?

  • Yeah, I'll take it 😎
@wpl-sf-nbirch wpl-sf-nbirch added the bug Used to mark issues with provider's incorrect behavior label Aug 15, 2024
@sfc-gh-jmichalak
Copy link
Collaborator

Hi @wpl-sf-nbirch 👋 Thanks for reporting this issue. We will rework this resource as stated in our roadmap.

@sfc-gh-jmichalak sfc-gh-jmichalak added the resource:table Issue connected to the snowflake_table resource label Aug 16, 2024
@pdreker
Copy link

pdreker commented Jan 23, 2025

As this is slated for a rework, I will just chime in, instead of opening a new issue, as it seems related:
When declaring a table with a column with a "NOT NULL" constraint and a default of "" the provider seems to not use the empty string as a default, due to the code in pkg/resources/table.go, L317 and following. In line 319 the code checks, if the passed in constant is longer than 0, which the empty string isn't and as such the code falls through and internally returns nil for the default, which runs afoul of the "NOT NULL" constraint and causes the provider to crash futher along the way very similar to what was reported here earlier.

@sfc-gh-jmichalak
Copy link
Collaborator

Hi @pdreker 👋 Thanks for reporting this. This is indeed a mistake in setting the column defaults. We'll address this while reworking the table resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to mark issues with provider's incorrect behavior resource:table Issue connected to the snowflake_table resource
Projects
None yet
Development

No branches or pull requests

3 participants