Skip to content

Fix setup_config append handling for multi-value fields#518

Closed
Moksha25-tech wants to merge 1 commit intocertego:developfrom
Moksha25-tech:fix-setup-config-multi-values
Closed

Fix setup_config append handling for multi-value fields#518
Moksha25-tech wants to merge 1 commit intocertego:developfrom
Moksha25-tech:fix-setup-config-multi-values

Conversation

@Moksha25-tech
Copy link

Summary

This PR fixes an issue in the setup_config management command where the --append option failed for multi-value (ArrayField) configuration fields when a single value was provided.

Previously, appending a single value caused incorrect iteration over individual characters instead of treating the input as a single list entry.

Changes

  • Normalize appended values so single inputs are converted into lists before processing
  • Preserve existing configuration values while avoiding duplicates during append
  • Ensure consistent behavior for both single-value and multi-value append operations
  • Add comprehensive test coverage for valid, invalid, and edge-case inputs

Testing

  • Added unit tests covering setup_config append behavior
  • All tests pass using:
docker compose run --rm buffalogs \
  python manage.py test impossible_travel.tests.task.test_management_commands

@Lorygold Lorygold closed this Jan 2, 2026
@Lorygold
Copy link
Contributor

@Moksha25-tech it seems to not work:
> ./manage.py setup_config -a filtered_alerts_types=["User Risk Threshold", "New Device"]

Returns:

sage: manage.py setup_config [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color] [--skip-checks]
                              [--execution_mode {manual,automatic}] [-o FIELD=[VALUES]] [-r FIELD=[VALUES]] [-a FIELD=[VALUES]] [--set-default-values] [--force]
manage.py setup_config: error: unrecognized arguments: New Device]

@Lorygold Lorygold reopened this Jan 12, 2026
@Lorygold
Copy link
Contributor

and linters failed in the CI

@Lorygold Lorygold marked this pull request as draft January 13, 2026 17:49
@Moksha25-tech
Copy link
Author

@Moksha25-tech it seems to not work: > ./manage.py setup_config -a filtered_alerts_types=["User Risk Threshold", "New Device"]

Returns:

sage: manage.py setup_config [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color] [--skip-checks]
                              [--execution_mode {manual,automatic}] [-o FIELD=[VALUES]] [-r FIELD=[VALUES]] [-a FIELD=[VALUES]] [--set-default-values] [--force]
manage.py setup_config: error: unrecognized arguments: New Device]

I will look into this again.

@Moksha25-tech Moksha25-tech force-pushed the fix-setup-config-multi-values branch from ec8b992 to 41c98d7 Compare February 16, 2026 12:31
@Moksha25-tech Moksha25-tech reopened this Feb 16, 2026
@Moksha25-tech Moksha25-tech marked this pull request as ready for review February 16, 2026 12:43
@Moksha25-tech
Copy link
Author

Hi @Lorygold

I have updated the PR to resolve the issues discussed. Here is a summary of the fixes:

  • Handled Multi-value Fields with Spaces: The setup_config command now correctly parses complex list inputs like ["User Risk Threshold", "New Device"].
  • Implemented Hybrid Parsing: I added a robust parse_field_value logic that uses json.loads for quoted lists while maintaining a fallback for the legacy comma-separated format used in existing tests.
  • Passed Local Test Suite

Code Patch Details:
I updated the parse_field_value function in impossible_travel/management/commands/setup_config.py as follows:

if value.startswith("[") and value.endswith("]"):
    try:
        # Standard JSON parsing for complex strings with spaces
        json_val = value.replace("'", '"')
        parsed_list = json.loads(json_val)
        parsed = [_cast_value(v) for v in (parsed_list if isinstance(parsed_list, list) else [parsed_list])]
    except json.JSONDecodeError:
        # Fallback for legacy comma-split cases to maintain test compatibility
        inner = value[1:-1].strip()
        parsed = [_cast_value(v.strip()) for v in inner.split(",") if v.strip()]

@Lorygold
Copy link
Contributor

Hi @Moksha25-tech , the unit tests are missed and in addition to that, the #562 PR has been completed, sorry for that but I didn't get responses about the task in the related issue, so I've assigned it again.

@Lorygold
Copy link
Contributor

@lucaCigarini @eugenioseveri this can be closed

Already solved by the PR #562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants