Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix TypeError in split_args function#86352

Open
Nicole-Dev24 wants to merge 1 commit intoansible:develfrom
Nicole-Dev24:normalize_split_args_input
Open

Fix TypeError in split_args function#86352
Nicole-Dev24 wants to merge 1 commit intoansible:develfrom
Nicole-Dev24:normalize_split_args_input

Conversation

@Nicole-Dev24
Copy link

SUMMARY

The split_args() function in ansible.module_utils.splitter crashes with a TypeError when processing normal string input in Python 3, due to the function attempting to split byte encoded strings using string delimiters. More specifically, the function originally encoded string input to bytes and then performed split operations on the bytes object using string delimiters (e.g., '\n' and ' '), causing a TypeError.

To fix the issue, if the input is a bytes object, it should be first decoded to a string before processing; thus, this matches the behavior of a similar function in ansible/parsing/splitter.py and ensures Python 3 compatibility. That is why I removed the args.encode('utf-8') and args.decode() logic, and added a check for byte input and decode it to a string if necessary using UTF-8 or Latin-1 encoding.

Fixes #86329 (Obs: discussions are still being made by the Ansible community in this issue).

ISSUE TYPE
  • Bugfix Pull Request

@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. has_issue needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 17, 2025
@ansibot
Copy link
Contributor

ansibot commented Dec 17, 2025

The test ansible-test sanity --test pep8 [explain] failed with 9 errors:

lib/ansible/module_utils/splitter.py:83:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:90:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:93:29: W291: trailing whitespace
lib/ansible/module_utils/splitter.py:101:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:115:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:137:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:188:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:202:1: W293: blank line contains whitespace
lib/ansible/module_utils/splitter.py:205:1: E303: too many blank lines (3)

The test ansible-test sanity --test pylint [explain] failed with 8 errors:

lib/ansible/module_utils/splitter.py:83:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:90:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:93:28: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:101:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:115:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:137:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:188:0: trailing-whitespace: Trailing whitespace
lib/ansible/module_utils/splitter.py:202:0: trailing-whitespace: Trailing whitespace

click here for bot help

@s-hertel
Copy link
Contributor

Not sure if I missed your response to #86329 (comment), but what is the use case?

@bcoca
Copy link
Member

bcoca commented Dec 17, 2025

#86329 (comment) as per my comment, I don't think that we should 'fix' this code, but either remove or consolidate the implementations

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Dec 31, 2025
@mattclay
Copy link
Member

mattclay commented Jan 7, 2026

I looked at usage of split_args on Galaxy and I'm not seeing any usage in modules or module_utils, only plugins, so I think it's reasonable to deprecate this instead of updating it.

@webknjaz webknjaz added the ci_verified Changes made in this PR are causing tests to fail. label Jan 8, 2026
@Nicole-Dev24
Copy link
Author

Not sure if I missed your response to #86329 (comment), but what is the use case?

While studying the Ansible codebase to better understand it before contributing, this piece of code caught my attention... So I decided to investigate it a little further

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug. ci_verified Changes made in this PR are causing tests to fail. has_issue needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split_args() fails due to bytes and str type mismatch

6 participants