PostgresHook: deepcopy connection to avoid mutating connection obj #15412
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.
PostgresHook: deepcopy connection object to avoid unexpected mutation
For AWS IAM based connections, the connection object is mutated by setting the
login
,password
andport
properties after the call toself.get_iam_token(...)
. The connection object'slogin
field is set to"IAM:original-login"
because thelogin
value returned hasIAM:
prefixed.As a result, any subsequent calls to
get_conn()
will fail with the AWSclient.get_cluster_credentials(...)
call complaining that:
cannot be part of theDbUser
argument.In general, the values within any connection objects used by this hook should not be subject to mutation by
get_conn()
calls, and the addition ofdeepcopy
is meant to enforce this.