Skip to content

Commit f6bb0de

Browse files
committed
Fix delimiter handling again for single column CSVs
1 parent d801392 commit f6bb0de

File tree

1 file changed

+17
-10
lines changed
  • app/apps/homeownerassociation/importers

1 file changed

+17
-10
lines changed

app/apps/homeownerassociation/importers/base.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,35 @@ def _read_csv(self, file_path: str) -> Tuple[List[str], List[Dict[str, str]]]:
122122

123123
# Handle single-column file (no delimiter)
124124
if delimiter is None:
125-
# Use CSV reader to properly handle quoted values
126-
csv_reader = csv.reader(io.StringIO(content))
127-
lines = [
128-
row
129-
for row in csv_reader
130-
if row and any(cell.strip() for cell in row)
131-
]
125+
# For single-column files, read line by line and handle quotes manually
126+
# Since there's no delimiter, we can't use csv.reader (it defaults to comma)
127+
lines_raw = content.strip().split("\n")
128+
lines = []
129+
for line in lines_raw:
130+
line = line.strip()
131+
if not line:
132+
continue
133+
# Handle quoted values: remove surrounding quotes and unescape internal quotes
134+
if line.startswith('"') and line.endswith('"'):
135+
# Remove surrounding quotes
136+
line = line[1:-1]
137+
# Replace escaped quotes (double quotes) with single quotes
138+
line = line.replace('""', '"')
139+
lines.append(line)
132140

133141
if not lines:
134142
raise ImportError("CSV file is empty")
135143

136144
# First line is the header
137-
header = lines[0][0].strip() if lines[0] else ""
145+
header = lines[0].strip()
138146
if not header:
139147
raise ImportError("CSV file has no headers")
140148

141149
headers = [header]
142150
rows = []
143151
# Process remaining lines as single-column values
144152
for line in lines[1:]:
145-
value = line[0].strip() if line else ""
146-
cleaned_row = {header: value}
153+
cleaned_row = {header: line.strip()}
147154
rows.append(cleaned_row)
148155
else:
149156
reader = csv.DictReader(io.StringIO(content), delimiter=delimiter)

0 commit comments

Comments
 (0)