Guard boto3_elasticsearch loading properly#58554
Conversation
|
Should this have a virtual, using the |
🤷♂️ I'm mostly thoughtlessly following the pattern of similar modules, e.g.: |
|
It looks like the pre-commit formatting somehow broke the tests. Edit, what had to be fixed: diff --git a/salt/modules/boto3_elasticsearch.py b/salt/modules/boto3_elasticsearch.py
index 3bffa5b9a2..f6ff673434 100644
--- a/salt/modules/boto3_elasticsearch.py
+++ b/salt/modules/boto3_elasticsearch.py
@@ -149,7 +149,9 @@ def add_tags(
if arn:
boto_params = {
"ARN": arn,
- "TagList": [{"Key": k, "Value": value} for k, value in tags or {}.items()],
+ "TagList": [
+ {"Key": k, "Value": value} for k, value in tags.items() or {}.items()
+ ],
}
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) |
ee75b13 to
c5ae4fb
Compare
There was a problem hiding this comment.
| {"Key": k, "Value": value} for k, value in tags.items() or {}.items() | |
| {"Key": k, "Value": value} for k, value in (tags or {}).items() |
Yeah, that pre-commit horked this line up completely. Something seems off with the indention here? but... this is the logic fix.
There was a problem hiding this comment.
I think what's in the PR right now is logically ok, but yours is clearer, I'll add that.
What the pre-commit did originally was change six.iteritems(tags or {}) to tags or {}.items(), which is definitely not ok!
There was a problem hiding this comment.
what's in the PR now will fail when tags is None:
>>> tags = None
>>> tags.items() or {}.items()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'items'
That was an implicit fallback with iteritems(tags or {}) 🙃
The other option would be tags.items() if tags else {}.items() but that would be silly 😂
There was a problem hiding this comment.
Ah, I see, the comprehension was changed: https://github.com/saltstack/salt/pull/58622/files#diff-fe8071ebcb4727856197b666dbf829930088a5d5fc5d8c82a0d806d03ecf059bR149
waynew
left a comment
There was a problem hiding this comment.
That comprehension needs some fixing.
I don't have strong feelings about tests here, but you could easily write two tests that cover both HAS_BOTO and not HAS_BOTO.
I still think that we want virtual to be returning false without boto though, right? If we don't have boto, we can't connect to elasticsearch... because we don't have boto?
|
oooh, I see what you mean. That check boto reqs probably returns false without boto 👍 |
bc2ffb5 to
93be6e9
Compare
There was a problem hiding this comment.
bad rebase, fixing
93be6e9 to
b44fb8e
Compare
b44fb8e to
93bcc74
Compare
|
Is this issue the same one being experienced here: I had initially added to the conversation in this issue because of all of these traceback error outputs in the debug log for |
@ScriptAutomate I think it's best to keep this separate. They're sort of related, in that they are both issues where a not-quite-right interaction between |
|
@major0 if you want to review or at least know about this PR simply letting you know :) |
|
@waynew can you re-review here |
What does this PR do?
Fixes this traceback on module loading, bringing
boto3_elasticsearchinto line with otherboto3modules.What issues does this PR fix or reference?
Fixes (partially): #55848
Merge requirements satisfied?
If tests are required for this, I need guidance.