Skip to content

Commit f03b2ba

Browse files
committed
Fix connections validaiton
1 parent 06c7c1e commit f03b2ba

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

src/superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55

6-
__version__ = "4.4.36dev1"
6+
__version__ = "4.4.35dev2"
77

88

99
os.environ.update({"sa_version": __version__})

src/superannotate/lib/core/usecases/annotations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,9 +2101,8 @@ def execute(self):
21012101
if categorization_enabled:
21022102
item_id_category_map = {}
21032103
for item_name in uploaded_annotations:
2104-
category = (
2105-
name_annotation_map[item_name]["metadata"]
2106-
.get("item_category", None)
2104+
category = name_annotation_map[item_name]["metadata"].get(
2105+
"item_category", None
21072106
)
21082107
if category:
21092108
item_id_category_map[name_item_map[item_name].id] = category

src/superannotate/lib/core/usecases/projects.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import decimal
22
import logging
3+
import math
34
from collections import defaultdict
45
from typing import List
56

@@ -608,10 +609,14 @@ def validate_project_type(self):
608609
def validate_connections(self):
609610
if not self._connections:
610611
return
611-
612-
if len(self._connections) > len(self._steps):
612+
if not all([len(i) == 2 for i in self._connections]):
613+
raise AppException("Invalid connections.")
614+
steps_count = len(self._steps)
615+
if len(self._connections) > max(
616+
math.factorial(steps_count) / (2 * math.factorial(steps_count - 2)), 1
617+
):
613618
raise AppValidationException(
614-
"Invalid connections: more connections than steps."
619+
"Invalid connections: duplicates in a connection group."
615620
)
616621

617622
possible_connections = set(range(1, len(self._steps) + 1))

tests/integration/steps/test_steps.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import json
2-
import os
3-
import tempfile
4-
from pathlib import Path
5-
6-
from numpy.ma.core import arange
71
from src.superannotate import AppException
82
from src.superannotate import SAClient
9-
from tests import DATA_SET_PATH
103
from tests.integration.base import BaseTestCase
114

125
sa = SAClient()
@@ -236,7 +229,8 @@ def test_create_invalid_connection(self):
236229
sa.set_project_steps(
237230
*args,
238231
connections=[
239-
[1, 2, 1],
232+
[1, 2],
233+
[2, 1],
240234
]
241235
)
242236
with self.assertRaisesRegexp(

0 commit comments

Comments
 (0)