Skip to content

Commit f344d9f

Browse files
authored
Merge pull request #2019 from cvisionai/rc/1.4.3
1.4.3 staging area
2 parents d4bd956 + 46984ae commit f344d9f

File tree

11 files changed

+320
-132
lines changed

11 files changed

+320
-132
lines changed

.circleci/config.yml

+93-21
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,48 @@ jobs:
186186
- attach_workspace:
187187
at: ~/
188188
- run:
189-
name: Initialize REST tests
190-
command: ssh lightsail 'cd tator && make testinit'
189+
name: Install xmlstarlet
190+
command: sudo apt-get update && sudo apt-get install -y xmlstarlet
191191
- run:
192192
name: Run REST tests
193193
command: |
194-
mkdir -p rest-test-results;
195-
ssh lightsail 'cd tator && for i in $(seq 1 3); do make rq-empty && make test && break || sleep 10; done;';
196-
ssh lightsail 'test -e tator/rest-junit.xml' && scp lightsail:tator/rest-junit.xml rest-test-results/ || exit 0;
197-
grep -q -E '\b[1-9][0-9]*\s+failed\b' rest-test-results/rest-junit.xml && exit 1 || exit 0;
194+
# Disable exit-on-error to allow all commands to run
195+
set +e
196+
197+
# Create directory for test results
198+
mkdir -p rest-test-results
199+
200+
# Run test initialization
201+
ssh -o "StrictHostKeyChecking=no" -o "ConnectTimeout=10" lightsail 'cd tator && make testinit'
202+
203+
# Run tests and capture exit status
204+
ssh -o "StrictHostKeyChecking=no" -o "ConnectTimeout=10" lightsail 'cd tator && make rq-empty && make test'
205+
TEST_EXIT_STATUS=$?
206+
207+
# Always attempt to copy the XML file
208+
ssh -o "StrictHostKeyChecking=no" -o "ConnectTimeout=10" lightsail 'test -e tator/rest-junit.xml' && \
209+
scp lightsail:tator/rest-junit.xml rest-test-results/ || echo "No test results found"
210+
211+
# Check if XML file was copied
212+
if [ -f rest-test-results/rest-junit.xml ]; then
213+
# Parse XML for failures or errors
214+
FAILURES=$(xmlstarlet sel -t -v "//testsuite/@failures" rest-test-results/rest-junit.xml)
215+
ERRORS=$(xmlstarlet sel -t -v "//testsuite/@errors" rest-test-results/rest-junit.xml)
216+
217+
if [ "$FAILURES" -gt 0 ] || [ "$ERRORS" -gt 0 ]; then
218+
echo "Test failures or errors detected"
219+
exit 1
220+
else
221+
echo "All tests passed"
222+
exit 0
223+
fi
224+
else
225+
echo "No test results found"
226+
if [ $TEST_EXIT_STATUS -ne 0 ]; then
227+
echo "Tests failed to run"
228+
fi
229+
exit 1
230+
fi
198231
- store_test_results:
199232
path: rest-test-results
200233
front-end-tests:
@@ -209,20 +242,38 @@ jobs:
209242
rsync -a --ignore-existing /home/circleci/.ssh/ lightsail:/home/ubuntu/.ssh/;
210243
ssh lightsail 'sed -i "s/circleci/ubuntu/g" ~/.ssh/config';
211244
- run:
212-
name: Install sshfs
213-
command: sudo -E apt-get update && sudo -E apt-get -yq --no-install-suggests --no-install-recommends install sshfs
245+
name: Install sshfs and xmlstarlet
246+
command: sudo -E apt-get update && sudo -E apt-get -yq --no-install-suggests --no-install-recommends install sshfs xmlstarlet
214247
- run:
215248
name: Front end tests
216249
no_output_timeout: 30m
217250
command: |
218-
ssh lightsail 'cd tator && make rq-empty';
219-
mkdir -p /tmp/videos;
220-
mkdir -p frontend-test-results;
221-
ssh lightsail 'mkdir -p /tmp/videos';
222-
sshfs -o default_permissions lightsail:/tmp/videos /tmp/videos;
223-
ssh lightsail 'mkdir -p /tmp/videos && export PATH=$PATH:$HOME/.local/bin:/snap/bin && export PYTHONUNBUFFERED=1 && cd tator && for i in $(seq 1 1); do if [ -d "test-results" ]; then rm -f test-results/*; else mkdir -p test-results; fi; python3 scripts/test_support/pytest_parallel.py --num-workers 3 test -n 2 --keep --base-url=http://localhost:8080 --browser=chromium --username=admin --password=admin --videos=/tmp/videos -s --junitxml=test-results/frontend-junit.xml && break || sleep 10; done;';
224-
ssh lightsail 'test -e tator/test-results/frontend-junit.xml' && scp lightsail:tator/test-results/frontend-junit.xml frontend-test-results/ || exit 0;
225-
grep -q -E '\b[1-9][0-9]*\s+failed\b' frontend-test-results/frontend-junit.xml && exit 1 || exit 0;
251+
set +e # Disable exit on error to ensure all commands run
252+
ssh lightsail 'cd tator && make rq-empty'
253+
mkdir -p /tmp/videos
254+
mkdir -p frontend-test-results
255+
ssh lightsail 'mkdir -p /tmp/videos'
256+
sshfs -o default_permissions lightsail:/tmp/videos /tmp/videos
257+
ssh lightsail 'export PATH=$PATH:$HOME/.local/bin:/snap/bin && export PYTHONUNBUFFERED=1 && cd tator && if [ -d "test-results" ]; then rm -f test-results/*; else mkdir -p test-results; fi; python3 scripts/test_support/pytest_parallel.py --num-workers 3 test -n 2 --keep --base-url=http://localhost:8080 --browser=chromium --username=admin --password=admin --videos=/tmp/videos -s --junitxml=test-results/frontend-junit.xml'
258+
TEST_EXIT_STATUS=$?
259+
ssh lightsail 'test -e tator/test-results/frontend-junit.xml' && scp lightsail:tator/test-results/frontend-junit.xml frontend-test-results/ || echo "No test results found"
260+
if [ -f frontend-test-results/frontend-junit.xml ]; then
261+
FAILURES=$(xmlstarlet sel -t -v "//testsuite/@failures" frontend-test-results/frontend-junit.xml)
262+
ERRORS=$(xmlstarlet sel -t -v "//testsuite/@errors" frontend-test-results/frontend-junit.xml)
263+
if [ "$FAILURES" -gt 0 ] || [ "$ERRORS" -gt 0 ]; then
264+
echo "Test failures or errors detected"
265+
exit 1
266+
else
267+
echo "All tests passed"
268+
exit 0
269+
fi
270+
else
271+
echo "No test results found"
272+
if [ $TEST_EXIT_STATUS -ne 0 ]; then
273+
echo "Tests failed to run"
274+
fi
275+
exit 1
276+
fi
226277
- store_test_results:
227278
path: frontend-test-results
228279
- store_artifacts:
@@ -235,22 +286,43 @@ jobs:
235286
steps:
236287
- attach_workspace:
237288
at: ~/
289+
- run:
290+
name: Install xmlstarlet
291+
command: sudo apt-get update && sudo apt-get install -y xmlstarlet
238292
- run:
239293
name: Copy test directories
240294
command: |
241295
ssh lightsail 'rm -rf ~/tator/tatorpy_test && cp -r ~/tator/scripts/packages/tator-py/test ~/tator/tatorpy_test && cp -r ~/tator/scripts/packages/tator-py/examples ~/tator/.';
242296
- run:
243297
name: Get API token
244298
command: |
245-
ssh lightsail "curl -d '{"'"username"'": "'"admin"'", "'"password"'": "'"admin"'", "'"refresh"'": true}' -H 'Content-Type: application/json' http://localhost:8080/rest/Token | jq '.token' | xargs printf '%b\n' | tee ~/token.txt;"
299+
ssh lightsail "curl -d '{\"username\": \"admin\", \"password\": \"admin\", \"refresh\": true}' -H 'Content-Type: application/json' http://localhost:8080/rest/Token | jq '.token' | xargs printf '%b\n' | tee ~/token.txt;"
246300
scp lightsail:~/token.txt ~/token.txt
247301
- run:
248302
name: Run tator-py tests
249303
command: |
250-
mkdir -p tatorpy-test-results;
251-
ssh lightsail 'export TATOR_TOKEN='"'$(cat ~/token.txt)'"'; export TATOR_HOST=http://localhost:8080; export PATH=$PATH:$HOME/.local/bin:/snap/bin && cd tator && for i in $(seq 1 3); do if [ -d "test-results" ]; then rm -f test-results/*; else mkdir -p test-results; fi; pytest tatorpy_test --run-alt-bucket --ignore tatorpy_test/test_algorithm_launch.py --ignore tatorpy_test/test_job_cancel.py --ignore tatorpy_test/test_hosted_template.py -s --keep --junitxml=test-results/tatorpy-junit.xml && break || sleep 10; done;';
252-
ssh lightsail 'test -e tator/test-results/tatorpy-junit.xml' && scp lightsail:tator/test-results/tatorpy-junit.xml tatorpy-test-results/ || exit 0;
253-
grep -q -E '\b[1-9][0-9]*\s+failed\b' tatorpy-test-results/tatorpy-junit.xml && exit 1 || exit 0;
304+
set +e # Disable exit on error to ensure all commands run
305+
mkdir -p tatorpy-test-results
306+
ssh lightsail 'export TATOR_TOKEN='"'$(cat ~/token.txt)'"'; export TATOR_HOST=http://localhost:8080; export PATH=$PATH:$HOME/.local/bin:/snap/bin && cd tator && if [ -d "test-results" ]; then rm -f test-results/*; else mkdir -p test-results; fi; pytest tatorpy_test --run-alt-bucket --ignore tatorpy_test/test_algorithm_launch.py --ignore tatorpy_test/test_job_cancel.py --ignore tatorpy_test/test_hosted_template.py -s --keep --junitxml=test-results/tatorpy-junit.xml'
307+
TEST_EXIT_STATUS=$?
308+
ssh lightsail 'test -e tator/test-results/tatorpy-junit.xml' && scp lightsail:tator/test-results/tatorpy-junit.xml tatorpy-test-results/ || echo "No test results found"
309+
if [ -f tatorpy-test-results/tatorpy-junit.xml ]; then
310+
FAILURES=$(xmlstarlet sel -t -v "//testsuite/@failures" tatorpy-test-results/tatorpy-junit.xml)
311+
ERRORS=$(xmlstarlet sel -t -v "//testsuite/@errors" tatorpy-test-results/tatorpy-junit.xml)
312+
if [ "$FAILURES" -gt 0 ] || [ "$ERRORS" -gt 0 ]; then
313+
echo "Test failures or errors detected"
314+
exit 1
315+
else
316+
echo "All tests passed"
317+
exit 0
318+
fi
319+
else
320+
echo "No test results found"
321+
if [ $TEST_EXIT_STATUS -ne 0 ]; then
322+
echo "Tests failed to run"
323+
fi
324+
exit 1
325+
fi
254326
- store_test_results:
255327
path: tatorpy-test-results
256328
- run:

api/main/rest/_annotation_query.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333

3434
def _do_object_search(qs, params):
3535
if params.get("object_search"):
36-
qs = get_attribute_psql_queryset_from_query_obj(qs, params.get("object_search"))
36+
qs = get_attribute_psql_queryset_from_query_obj(
37+
params["project"], qs, params.get("object_search")
38+
)
3739

3840
# Used by GET queries
3941
if params.get("encoded_search"):
4042
search_obj = json.loads(base64.b64decode(params.get("encoded_search").encode()).decode())
41-
qs = get_attribute_psql_queryset_from_query_obj(qs, search_obj)
43+
qs = get_attribute_psql_queryset_from_query_obj(params["project"], qs, search_obj)
4244

4345
return qs
4446

@@ -141,7 +143,7 @@ def _get_annotation_psql_queryset(project, filter_ops, params, annotation_type):
141143
)
142144
if filter_type is not None:
143145
qs = get_attribute_psql_queryset(
144-
ANNOTATION_TYPE_LOOKUP[annotation_type].objects.get(pk=filter_type),
146+
ANNOTATION_TYPE_LOOKUP[annotation_type].objects.filter(pk=filter_type).values("pk", "attribute_types").first(),
145147
qs,
146148
params,
147149
filter_ops,
@@ -155,10 +157,10 @@ def _get_annotation_psql_queryset(project, filter_ops, params, annotation_type):
155157
)
156158
elif filter_ops or params.get("float_array", None):
157159
queries = []
158-
for entity_type in ANNOTATION_TYPE_LOOKUP[annotation_type].objects.filter(project=project):
160+
for entity_type in ANNOTATION_TYPE_LOOKUP[annotation_type].objects.filter(project=project).values('pk', 'attribute_types'):
159161
sub_qs = get_attribute_psql_queryset(entity_type, qs, params, filter_ops)
160162
if type(sub_qs) != type(None):
161-
queries.append(sub_qs.filter(type=entity_type))
163+
queries.append(sub_qs.filter(type=entity_type['pk']))
162164
logger.info(f"Joining {len(queries)} queries together.")
163165
sub_qs = queries.pop()
164166
if queries:
@@ -183,7 +185,9 @@ def _get_annotation_psql_queryset(project, filter_ops, params, annotation_type):
183185
media_qs = media_qs.filter(pk__in=section.media.values("id"))
184186
elif section.dtype == "saved_search":
185187
if object_search:
186-
media_qs = get_attribute_psql_queryset_from_query_obj(media_qs, object_search)
188+
media_qs = get_attribute_psql_queryset_from_query_obj(
189+
project, media_qs, object_search
190+
)
187191
elif related_object_search:
188192
media_state_types = StateType.objects.filter(project=project)
189193
media_localization_types = Localization.objects.filter(project=project)
@@ -210,7 +214,7 @@ def _get_annotation_psql_queryset(project, filter_ops, params, annotation_type):
210214
faux_params = {key.replace("related_", ""): params[key] for key in matches}
211215
logger.info(faux_params)
212216
related_matches = []
213-
for entity_type in related_media_types:
217+
for entity_type in related_media_types.values('pk', 'attribute_types'):
214218
faux_filter_ops = get_attribute_filter_ops(faux_params, entity_type)
215219
if faux_filter_ops:
216220
related_matches.append(
@@ -236,7 +240,7 @@ def _get_annotation_psql_queryset(project, filter_ops, params, annotation_type):
236240
related_matches = []
237241
for entity_type in related_media_types:
238242
media_qs = Media.objects.filter(project=project, type=entity_type)
239-
media_qs = get_attribute_psql_queryset_from_query_obj(media_qs, search_obj)
243+
media_qs = get_attribute_psql_queryset_from_query_obj(project, media_qs, search_obj)
240244
if media_qs.exists():
241245
related_matches.append(media_qs)
242246
if related_matches:
@@ -294,7 +298,7 @@ def get_annotation_queryset(project, params, annotation_type):
294298
types = ANNOTATION_TYPE_LOOKUP[annotation_type].objects.filter(pk=filter_type)
295299
else:
296300
types = ANNOTATION_TYPE_LOOKUP[annotation_type].objects.filter(project=project)
297-
for entity_type in types:
301+
for entity_type in types.values("pk", "attribute_types"):
298302
filter_ops.extend(get_attribute_filter_ops(params, entity_type))
299303
qs = _get_annotation_psql_queryset(project, filter_ops, params, annotation_type)
300304
return qs

0 commit comments

Comments
 (0)