-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Fix grafana_dashboard py2/3 compatibility #49194
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi @jqueuniet, thank you for submitting this pull-request! |
@pilou- Could you review? |
seuf
approved these changes
Dec 7, 2018
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.
I've tried both python2.7 and python 3 and it worked for me.
Thanks for your contribution 😃
LGTM
rebuild_merge Once merged please raise a backport PR including a changelog/fragment |
kbreit
pushed a commit
to kbreit/ansible
that referenced
this pull request
Jan 11, 2019
* Fix grafana_dashboard py2 compatibility * Convert URL output to a text/unicode string for json.loads
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
affects_2.8
This issue/PR affects Ansible v2.8
bug
This issue/PR relates to a bug.
community_review
In order to be merged, this PR must follow the community review workflow.
grafana
Grafana community
module
This issue/PR relates to a module.
python3
support:community
This issue/PR relates to code supported by the Ansible community.
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.
SUMMARY
Fix grafana_dashboard Python 2 compatibility
ISSUE TYPE
COMPONENT NAME
grafana_dashboard
ADDITIONAL INFORMATION
Merge request #47708 added a regression with Python 2, causing the following error:
failed: [grafana-infra-000] (item=['node_exporter.json', 'prometheus-infra-000']) => {"changed": false, "item": ["node_exporter.json", "prometheus-infra-000"], "msg": "error : descriptor 'split' requires a 'str' object but received a 'unicode'"}
Issue was the
json.loads
in the Grafana version check returned aunicode
variable, incompatible withstr.split
.I switched to using the split method from the returned object, either
str.split
orunicode.split
depending on the type. The integer cast at the end of the function works with either type and normalizes the function output.I also got the following error testing this fix for Python 3, also in the Grafana version check, and tried to correct it too:
failed: [grafana-infra-000] (item=['node_exporter.json', 'prometheus-infra-000']) => {"changed": false, "item": ["node_exporter.json", "prometheus-infra-000"], "msg": "error : the JSON object must be str, not 'bytes'"}
This time, it was the
json.loads
that was choking on abytes
object. I added a call to theto_text
function to handle this issue, and added a case forUnicodeError
in the exception handling.Some data on my environment: