Skip to content
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

simplify value conversion by removing ast.literal_eval #675

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/utils.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Simplifies value handling by returning direct string conversion instead of using ast.literal_eval
10 changes: 5 additions & 5 deletions plugins/module_utils/network/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,11 @@ def __call__(self, value, variables=None, fail_on_undefined=True):
return None
raise

if value:
try:
return ast.literal_eval(value)
except Exception:
return str(value)
if value is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AAYUSH2091 we generally put try and exception block to handle corner cases so i dont think removing this would be a good option here, so you might wanna revert it back if thats not something blocking you but we cant just refactor the code this way, this might open other potential problems/errors for us.

# Special handling for values starting with +
if isinstance(value, str) and value.startswith("+"):
return value # Keep the + prefix intact
return str(value) # Convert everything else to string
else:
return None

Expand Down
Loading