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

"sql: no rows in result set" error #188

Closed
pwnage101 opened this issue May 6, 2020 · 4 comments · Fixed by #339
Closed

"sql: no rows in result set" error #188

pwnage101 opened this issue May 6, 2020 · 4 comments · Fixed by #339
Labels
bug Used to mark issues with provider's incorrect behavior

Comments

@pwnage101
Copy link
Contributor

We occasionally encounter this error when trying to run plan/refresh after a failed apply (e.g. can happen if the computer running apply gets terminated or if snowflake throws an error in the middle of an apply, like if we're trying to make terraform create an object that already exists...there are many reasons why an apply will error out without cleaning itself up):

$ terraform refresh
... (a bunch of "Refreshing state..." lines)

Error: sql: no rows in result set

We typically remedy the issue by deleting grants from the state that don't exist in Snowflake, but it can be extremely difficult to manually find those instances since our terraform state has thousands of resources.

I think there's some grant-related code in the provider that is running a SQL query to get a list of grants and just blindly expecting the result to be non-empty. I think the provider needs to handle this more elegantly, because I would hope that terraform refresh should be more robust since it is a prerequisite to running terraform plan and apply.

Aside: It is no surprise that the state is corrupt, since we ARE talking about the apply unexpectedly exiting or getting terminated. So I agree that there are other provider bugs and issues with our infrastructure which must first exist and have happened before we encounter this bug, but I would rather treat those as separate bugs. Since this happens to us so often and it's always the same error, I feel like fixing this is the low-hanging fruit.

@ryanking ryanking added the bug Used to mark issues with provider's incorrect behavior label May 6, 2020
@swathiJayav
Copy link

We are also experiencing this bug.

@ryanking
Copy link
Contributor

I think what we need to do is set the id of unfound resources to "", which will effectively remove them from the state for you.

I don't have a good way to test this though. @pwnage101 do you have a reproducible failure here?

@ryanking
Copy link
Contributor

Leaving more note here in case someone wants to pick this work up - it seems that in our read paths we need to figure out errors that mean "resource doesn't exist" and in those cases call d.SetId("") to remove the resource from the state. Given the way our code for reading grants is written, this might take a fair bit of refactoring to achieve. Doing it in pieces would be fine.

Example of what I am talking about from the aws provider (reading that provider is how I figure out how to do things in providers.

ryanking added a commit that referenced this issue Dec 9, 2020
This PR is a redo of #305, since it was missing tests and some resources were not working.

Fixes #188 

Co-authored-by: Edwin De Jong <edwin.de.jong@bigdatarepublic.nl>
Co-authored-by: Ryan King <rking@chanzuckerberg.com>
gjv9491 pushed a commit to gjv9491/terraform-provider-snowflake that referenced this issue Mar 19, 2021
…s#339)

This PR is a redo of Snowflake-Labs#305, since it was missing tests and some resources were not working.

Fixes Snowflake-Labs#188 

Co-authored-by: Edwin De Jong <edwin.de.jong@bigdatarepublic.nl>
Co-authored-by: Ryan King <rking@chanzuckerberg.com>
anton-chekanov pushed a commit to anton-chekanov/terraform-provider-snowflake that referenced this issue Jan 25, 2022
…s#339)

This PR is a redo of Snowflake-Labs#305, since it was missing tests and some resources were not working.

Fixes Snowflake-Labs#188 

Co-authored-by: Edwin De Jong <edwin.de.jong@bigdatarepublic.nl>
Co-authored-by: Ryan King <rking@chanzuckerberg.com>
daniepett pushed a commit to daniepett/terraform-provider-snowflake that referenced this issue Feb 9, 2022
…s#339)

This PR is a redo of Snowflake-Labs#305, since it was missing tests and some resources were not working.

Fixes Snowflake-Labs#188 

Co-authored-by: Edwin De Jong <edwin.de.jong@bigdatarepublic.nl>
Co-authored-by: Ryan King <rking@chanzuckerberg.com>
@luis02lopez
Copy link

Happening here with a terraform import

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants