ModelEngine-Group / ModelEngine-Group/nexent

`convert_string_to_list` silently drops negative integers and non-digit entries

Open Beginner friendly
#3,818 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.9k
Forks
731
Avg merge
19h 34m
Merged PRs (30d)
172

Description

backend/utils/str_utils.py:27-39:

def convert_string_to_list(items_str: Optional[str]) -> List[int]:
    """Convert comma-separated string to list of integers for processing"""
    if not items_str or items_str.strip() == "":
        return []
    return [int(item.strip()) for item in items_str.split(",") if item.strip().isdigit()]

Two related bugs in one line:

  1. str.isdigit() returns False for "-1", "+1", and " 3 " (after strip() only stripped outer whitespace — fine — but for any digit-with-sign it's False). The companion convert_list_to_string (line 12) happily emits a negative integer; round-tripping a list containing -1 therefore drops it silently.
  2. Non-digit garbage like "a,1,b,2" is silently filtered to [1, 2]. There's no warning, no exception, and no log line — the caller has no way to distinguish "no values supplied" from "your input was malformed".
Repro
>>> convert_string_to_list(convert_list_to_string([1, -2, 3]))
[1, 3]
>>> convert_string_to_list("a, 1, b, 2")
[1, 2]   # silently dropped 'a' and 'b'
Suggested fix
def convert_string_to_list(items_str: Optional[str]) -> List[int]:
    if not items_str or not items_str.strip():
        return []
    out = []
    for raw in items_str.split(","):
        item = raw.strip()
        if not item:
            continue
        try:
            out.append(int(item))
        except ValueError:
            logger.warning("convert_string_to_list: dropping non-integer entry %r", item)
    return out

That preserves negatives, surfaces malformed input via logs, and keeps the same return shape.

Category: A (logic/correctness). Severity: Low–Medium depending on where the round-trip is used in the DB layer.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in backend/utils/str_utils.py, reading convert_list_to_string at line 12 and convert_string_to_list at lines 27-39. Verify the round-trip examples and malformed-entry behavior described in the issue. Done means negative and signed integers are preserved, malformed entries produce warnings instead of being silently indistinguishable, and the return shape remains a list of integers.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.