refactor: modernize UserItem.CSVImport - use csv module for parsing

Open
#1,846 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
backend

Research direction

Start with UserItem.CSVImport, validate_file_for_import, _validate_import_line_or_throw, and create_user_from_line, then inspect test_password_with_comma_partially_masks. Done means parsing and username extraction use csv handling, and empty-input and too-many-column errors follow one convention.

Written by the indexing model from the issue text.

Description

UserItem.CSVImport has some internal design smells worth cleaning up.

1. Use the csv module for parsing. Today the code does line.split(","), which misaligns whenever a field contains a comma - a password like "my,pa\$\$w0rd", a display name like "Smith, John". The column-1 mask added in #1829 only covers what lands in column 1; bytes that spill into column 2+ still leak (see test_password_with_comma_partially_masks). csv.reader also handles quoted values, CRLF, and BOM deliberately rather than coincidentally.

2. Consolidate two username extractions. validate_file_for_import uses line.partition(",")[0].strip(), while _validate_import_line_or_throw uses list(map(str.strip, line.split(",")))[USERNAME]. Same result today, but a maintenance hazard. A csv.reader migration collapses both.

3. Align error handling in create_user_from_line. It returns None for empty input but raises ValueError for too many columns. Pick one convention.

🤖 Generated with Claude Code

Dominant language
Python
Stars
716
Forks
446
Avg merge
8d 8h
Merged PRs (30d)
2

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.

More from tableau/server-client-python

All issues in tableau/server-client-python

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.