-
Notifications
You must be signed in to change notification settings - Fork 16.4k
introduce a method to convert dictionaries to boto-style key-value lists #28816
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
Conversation
|
@vandonr-amz One possible side effect of this change - I think Airflow still can't render dictionaries keys if it templated value: #18938 |
wow that PR is an adventure... sad to see it doesn't have a happy ending |
However, I don't really see why you'd want to template dictionary keys. Templating values makes sense, but keys should be pretty much constant |
I don't. My opinion that AWS resource Tag name (key) should be consistent or all idea would be broken and turned into the mess. However we don't know user cases, so at least we should add info that behaviour with dict-style could be different rather then use native AWS API style (this is not boto3 behaviour this how what AWS API expected this parameters) |
|
Also I think we need to keep compatibility with native API parts. I mean it would be nice if function check (btw i think you forget to add it into the PR) if value are dictionary then convert it to appropriate format, if not.. well then return as is or check if this has appropriate format. Actually I also work on the same issue in the past, I don't remember when I didn't finish it, may be because I could't cover all cases or something like that. I've prepare GIST based on some past findings, it is not concern that we should do by this way, just an example. It use additional ability of Airflow render particular attributes from inner object |
|
oh so you mean we should always accept either preformated or as a dict. Yeah why not, I can do that. |
b7ab4f6 to
889d9a7
Compare
|
ok, made it accept a list or dict where meaningful, and added the missing file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
-
Please separate out the SageMakerCreateExperimentOperator changesEdit: ah right, okay. -
Can this be more-universal across the provider? There are likely other operators that have the same thing, ISTR there are some EC2 operators.
-
Do we show a concrete example of the two styles anywhere in the docs?
I'm not sure where the best place might be? It almost feels like it should be in a "top level" section like https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/index.html ? WDYT?
I didn't find other examples of this pattern in the AWS package, RDS, Sagemaker and S3 are the only 3 that popped up, but also it's a bit hard to grep for this.
No I don't think we do. It's true that it might be good to have it somewhere, but also, I'd hope for new users to use the dictionary approach, which is a lot more intuitive. I'd rather copy-paste an example in every docstring where necessary. |
I know a lot of samples where same approaches uses... but all of them inside of huge object structure. For example in Batch client:
So end users might also use this function for produce this objects (I don't think we should help them with this) by just provide dict and appropriate mapping for key_label and value_label.
Some almost same function I use in the past in Airflow 1.10.x: def aws_batch_env(d):
return [{"name": k, "value": v} for k, v in d.items()]
...
batch_env = {
"VAR_1": "{{ ti.xcom_pull(task_ids='foo') }}",
"VAR_2": "{{ ti.xcom_pull(task_ids='bar') }}",
...
"VAR_n": "{{ ti.xcom_pull(task_ids='spam') }}",
}
batch_task = BatchOperator(
...
overrides={
"environment": aws_batch_env(batch_env)
},
) |
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Boto expects key/value lists in a weird format that's not super user friendly. I think we should offer a pleasant interface to the users, so we should accept regular python dictionaries and do the transformation ourselves when possible. I added a method to this effect, and plugged it in where I could see this pattern.