Skip to content

Commit 83f96b8

Browse files
authored
Merge pull request #143 from WikiMovimentoBrasil/2025-01-fix-csv-aliases
fix: csv aliases should be a list of alias, like in v1
2 parents 5c46ebb + 8c2a38a commit 83f96b8

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/core/parsers/csv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def parse_line(self, row, header):
127127
current_command["site"] = lang
128128
else:
129129
current_command["language"] = lang
130+
# Code expects aliases to be a list of alias, like in v1
131+
if current_command["what"] == "alias":
132+
current_command["value"]["type"] = "aliases"
133+
current_command["value"]["value"] = [current_command["value"]["value"]]
130134

131135
commands.append(current_command)
132136

src/core/parsers/v1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ def parse_statement(self, elements, first_command):
9696
vvalue = self.parse_value(elements[2])
9797

9898
if llen >= 3 and elements[1][0] == "A":
99-
labels = []
99+
aliases = []
100100
lang = elements[1][1:]
101101
for el in elements[2:]:
102-
vlabel = self.parse_value(el.strip())
103-
if not vlabel or vlabel["type"] != "string":
102+
valias = self.parse_value(el.strip())
103+
if not valias or valias["type"] != "string":
104104
raise ParserException("alias must be a string instance")
105-
labels.append(vlabel["value"])
106-
data = {"action": "add", "what": "alias", "language": lang, "item": entity, "value": {"type": "labels", "value": labels}}
105+
aliases.append(valias["value"])
106+
data = {"action": "add", "what": "alias", "language": lang, "item": entity, "value": {"type": "aliases", "value": aliases}}
107107

108108
elif llen == 3 and elements[1][0] in ["L", "D", "S"]:
109109
# We are adding / removing a LABEL, ALIAS, DESCRIPTION or SITELINK to our property

src/core/tests/test_batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def test_add_alias(self):
505505
{
506506
"action": "add",
507507
"item": "Q411518",
508-
"value": {"type": "string", "value": "Sandbox 3"},
508+
"value": {"type": "aliases", "value": ["Sandbox 3"]},
509509
"what": "alias",
510510
"language": "pt",
511511
},
@@ -516,7 +516,7 @@ def test_add_alias(self):
516516
{
517517
"action": "add",
518518
"item": "Q411518",
519-
"value": {"type": "string", "value": "Patterns, Predictors, and Outcome and Questions"},
519+
"value": {"type": "aliases", "value": ["Patterns, Predictors, and Outcome and Questions"]},
520520
"what": "alias",
521521
"language": "pt",
522522
},
@@ -608,7 +608,7 @@ def test_full_command(self):
608608
{
609609
"action": "add",
610610
"item": "Q4115189",
611-
"value": {"type": "string", "value": "Douglas Noël Adams"},
611+
"value": {"type": "aliases", "value": ["Douglas Noël Adams"]},
612612
"what": "alias",
613613
"language": "en",
614614
},

src/core/tests/test_csv_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def test_parse_alias(self):
556556
{
557557
"action": "add",
558558
"item": "Q4115189",
559-
"value": {"type": "string", "value": "Chacara Santo Antonio"},
559+
"value": {"type": "aliases", "value": ["Chacara Santo Antonio"]},
560560
"what": "alias",
561561
"language": "pt",
562562
},

src/core/tests/test_v1_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def test_v1_add_alias(self):
215215
"what": "alias",
216216
"item": "Q1234",
217217
"language": "pt",
218-
"value": {"type": "labels", "value": ["Texto brasileiro"]},
218+
"value": {"type": "aliases", "value": ["Texto brasileiro"]},
219219
},
220220
)
221221

0 commit comments

Comments
 (0)