Wrong AWS profile being retrieved in case of non default profile configured #124
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is already an issue reported by another user which I was able to reproduce in a slightly different scenario, but the error and conditions are apparently the same: #118
I drilled down and was able to identify the exact error scenario, steps to reproduce:
credentials:
config:
In the first time it will be created fine, but in the second, when it has to run the macro drop_relation (which maps to the python function clean_up_table), there will be an error in the dbt logs:
17:44:02.203689 [debug] [Thread-1 ]: Athena adapter: Error running SQL: macro drop_relation
17:44:02.212093 [error] [MainThread]: local variable 'table' referenced before assignment
Which when debugged from within python, inside the function clean_up_table, you notice the following:
So I noticed that the profile being used by boto3 was the default, it was trying to use my default profile AWS credentials to run this command, which justifies the credentials error. I have also tested that without specifying a profile (so it tries to get the default one) this error doesn't occur.
The solution is very specific to the problem I had, but I believe it might be an issue for the other functions that use the same logic to acquire a client, I just don't have scenarios to test all of them so changed only this one. I tried to look for an earlier place in the code to put this so it would already be the default when needed and this function wouldn't have to worry about it, but since we only have the profile after opening the connection, this is the best I could do, please let me know if you can see a better place to put this.