Skip to content

Commit 7294c17

Browse files
bosdbosd
authored andcommitted
fix(cli): Correctly parse groupby parameter
The `--groupby` command-line argument was not being parsed correctly, causing issues when the column name contained special characters like '/'. The argument was being treated as a sequence of characters instead of a single string. This change modifies the `import_cmd` function in `src/odoo_data_flow/__main__.py` to split the `groupby` string by commas, allowing for both single-column names with special characters and multiple comma-separated columns to be parsed correctly into a list of strings. Additionally, new tests have been added to `tests/test_import_threaded.py` to verify the fix and prevent future regressions. The `noxfile.py` was also updated to ensure the `pydoclint` linter runs correctly within the `pre-commit` session.
1 parent 37d485b commit 7294c17

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def precommit(session: nox.Session) -> None:
128128
"lint",
129129
external=True,
130130
)
131+
session.install("pydoclint")
131132
session.run("pre-commit", *args, external=True)
132133
if args and args[0] == "install":
133134
activate_virtualenv_in_precommit_hooks(session)

src/odoo_data_flow/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ def import_cmd(connection_file: str, **kwargs: Any) -> None:
311311
except (ValueError, SyntaxError) as e:
312312
log.error(f"Invalid --context dictionary provided: {e}")
313313
return
314+
315+
groupby = kwargs.get("groupby")
316+
if groupby is not None:
317+
kwargs["groupby"] = [col.strip() for col in groupby.split(",") if col.strip()]
318+
314319
run_import(**kwargs)
315320

316321

tests/test_import_threaded.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,38 @@ def test_recursive_batching_group_col_not_found(self) -> None:
661661
mock_log.error.assert_called_once_with(
662662
"Grouping column 'non_existent' not found. Cannot use --groupby."
663663
)
664+
665+
def test_recursive_batching_with_special_chars_in_col_name(self) -> None:
666+
"""Test batching with special characters in column names."""
667+
from odoo_data_flow.import_threaded import _recursive_create_batches
668+
669+
header = ["id", "name", "partner_id/id"]
670+
data = [
671+
["1", "A", "p1"],
672+
["2", "B", "p1"],
673+
["3", "C", "p2"],
674+
]
675+
batches = list(
676+
_recursive_create_batches(data, ["partner_id/id"], header, 10, False)
677+
)
678+
assert len(batches) == 2
679+
assert batches[0][1][0][2] == "p1"
680+
assert batches[1][1][0][2] == "p2"
681+
682+
def test_recursive_batching_multiple_cols_with_special_chars(self) -> None:
683+
"""Test batching with multiple columns, one with special characters."""
684+
from odoo_data_flow.import_threaded import _recursive_create_batches
685+
686+
header = ["id", "name", "partner_id/id", "company_id"]
687+
data = [
688+
["1", "A", "p1", "c1"],
689+
["2", "B", "p1", "c2"],
690+
["3", "C", "p2", "c1"],
691+
["4", "D", "p1", "c1"],
692+
]
693+
batches = list(
694+
_recursive_create_batches(
695+
data, ["partner_id/id", "company_id"], header, 10, False
696+
)
697+
)
698+
assert len(batches) == 3

0 commit comments

Comments
 (0)