Skip to content

API: GET /api/v2/tests/ ignores 'ordering' query parameter #14875

@plzthx

Description

@plzthx

Description

The ordering query parameter is silently ignored on the /api/v2/tests/ endpoint. Requests with ?ordering=-id or ?ordering=-pk return results sorted in ascending order by ID regardless of the parameter. This breaks client code expecting reverse-chronological (newest-first) ordering and contradicts Django REST Framework's standard behavior when OrderingFilter is properly configured.

Steps to Reproduce

# Fetch tests, explicitly request reverse ID order
curl -H "Authorization: Token YOUR_TOKEN" \
  "https://your-dd-instance/api/v2/tests/?ordering=-id&limit=5"

# Observe results are sorted by id ASC, not DESC as requested
# Verify with ?ordering=-pk — same result

Expected vs Actual

  • Expected: Results sorted DESC by id (newest first), matching the -id parameter
  • Actual: Results sorted ASC by id (oldest first), parameter ignored

Root Cause & Fix

The TestViewSet likely lacks OrderingFilter in filter_backends or doesn't list sortable fields in ordering_fields. Likely fix in dojo/api/v2/views.py TestViewSet:

class TestViewSet(...):
    filter_backends = [DjangoFilterBackend, OrderingFilter]  # Add OrderingFilter
    ordering_fields = ['id', 'created', 'updated', '-id', '-created']  # Include id
    ordering = ['-id']  # Default to newest first

Environment

  • DefectDojo: 2.57.2
  • Endpoint: GET /api/v2/tests/?ordering=...
  • Likely affects other list endpoints similarly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions