Skip to content

Commit 3ea10c3

Browse files
authored
Merge pull request #402 from wikimediabrasil/fix-396
Show error commands instead of ignoring them
2 parents babd2a1 + 38a9f36 commit 3ea10c3

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/core/parsers/v1.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def parse_statement(self, elements, first_command):
129129
llen = len(elements)
130130
if llen < 3:
131131
raise ParserException(
132-
"STATEMENT must contain at least entity, property and value"
132+
"Statement must contain at least entity, property and value"
133133
)
134134

135135
if first_command[0] == "-":
@@ -189,7 +189,7 @@ def parse_statement(self, elements, first_command):
189189
# We are adding / removing values
190190
pproperty = elements[1]
191191
if not self.is_valid_property_id(pproperty):
192-
raise ParserException(f"Invalid property {pproperty}")
192+
raise ParserException(f"Invalid property '{pproperty}'")
193193

194194
data = {
195195
"action": action,
@@ -390,5 +390,4 @@ def restore_placeholders(command):
390390
bc.status = BatchCommand.STATUS_ERROR
391391
bc.message = e.message
392392

393-
if bc.json:
394-
yield bc
393+
yield bc

src/core/tests/test_batch.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,21 @@ def test_remove_reference(self):
354354
],
355355
)
356356

357+
def test_errors(self):
358+
v1 = V1CommandParser()
359+
batch = BatchFactory.load_from_parser(
360+
v1, "b", "u", """CREATE||LAST|abc|123||xyz"""
361+
)
362+
cmd0 = batch.commands()[0]
363+
cmd1 = batch.commands()[1]
364+
cmd2 = batch.commands()[2]
365+
self.assertEqual(len(batch.commands()), 3)
366+
self.assertEqual(cmd0.status,BatchCommand.STATUS_INITIAL)
367+
self.assertEqual(cmd1.status,BatchCommand.STATUS_ERROR)
368+
self.assertEqual(cmd1.message, "Invalid property 'abc'")
369+
self.assertEqual(cmd2.status,BatchCommand.STATUS_ERROR)
370+
self.assertEqual(cmd2.message, "Statement must contain at least entity, property and value")
371+
357372

358373
class TestCSVBatch(TestCase):
359374
def test_create_property(self):

src/web/views/new_batch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,14 @@ def new_batch(request):
188188
combine_commands="do_not_combine_commands" not in request.POST,
189189
)
190190

191+
all_errors = True
191192
for batch_command in parser.parse(batch_commands):
193+
if batch_command.status != BatchCommand.STATUS_ERROR:
194+
all_errors = False
192195
batch_command.batch = batch
193196
batch_command.save()
194197

195-
if not batch.batchcommand_set.exists():
198+
if not batch.batchcommand_set.exists() or all_errors:
196199
raise ParserException(
197200
pgettext_lazy(
198201
"batch-py-valid-command-not-found",

0 commit comments

Comments
 (0)