Skip to content

Conversation

@moijes12
Copy link
Contributor

@moijes12 moijes12 commented Jan 5, 2026

This PR resolves a 500 error encountered when accessing the /docs/ and /api/schema/ endpoints. The issue was caused by incompatibilities between django-filter and djangorestframework's schema generation, as well as missing attributes in specific API views.

  • Add TreeherderFilterBackend to implement missing get_schema_operation_parameters method in DjangoFilterBackend.
  • Update DEFAULT_FILTER_BACKENDS and performance_data.py viewsets to use the new custom backend.
  • Change PerformanceJobViewSet to inherit from ViewSet to avoid serializer_class assertion errors.
  • Fix AttributeError in PerfCompareResults.get_serializer_class when request is None during schema generation.
  • Rename typos in DetailsPanel.jsx and PerformanceJobViewSet for consistency.

@jmaher @gmierz

Fixes Bug 1928549

@moijes12 moijes12 changed the title Bug 1998273: Fix API schema generation and 500 error on docs page Bug 1928549: Fix API schema generation and 500 error on docs page Jan 5, 2026
@moijes12
Copy link
Contributor Author

moijes12 commented Jan 6, 2026

@bhearsum Please can you review this if you get some time

@bhearsum
Copy link
Collaborator

bhearsum commented Jan 6, 2026

I'm not actually a reviewer for Treeherder.... @Archaeopteryx ?

@moijes12
Copy link
Contributor Author

moijes12 commented Jan 6, 2026

No problem. Thanks @bhearsum



class PerfomanceJobViewSet(viewsets.ReadOnlyModelViewSet):
class PerformanceJobViewSet(viewsets.ViewSet):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing these typos while you were here :)

@gmierz
Copy link
Collaborator

gmierz commented Jan 9, 2026

Hi @moijes12, thanks for looking into this!

I see that there was a patch for django-filter that should have added the get_schema_operation_parameters quite a while ago here: https://github.com/carltongibson/django-filter/pull/1086/files

So it seems odd that we still need a custom filter backend for it - would you know why? It makes me wonder if there's a better solution that could fix this issue for us.

@moijes12
Copy link
Contributor Author

Thanks @gmierz for your feedback

I did try with the latest django-filter (version 25.2) and it did seem odd to me that it still did not work. However, I will give it a second shot and get back.

This fixes the 500 error preventing the API documentation from loading
by doing the below:
* Add `TreeherderFilterBackend` to implement missing `get_schema_operation_parameters` method in `DjangoFilterBackend`.
* Update `DEFAULT_FILTER_BACKENDS` and `performance_data.py` viewsets to use the new custom backend.
* Change `PerformanceJobViewSet` to inherit from ViewSet to avoid `serializer_class` assertion errors.
* Fix `AttributeError` in `PerfCompareResults.get_serializer_class` when request is `None` during schema generation.
* Rename typos in DetailsPanel.jsx and PerformanceJobViewSet for consistency.

Fixes Bug 1998273
django-filter recommends using drf_spectacular for generating
OpenAPI schemas with DRF. See https://github.com/carltongibson/django-filter/blob/main/CHANGES.rst

This change adds drf_spectacular for schema generation in
settings. Also, the views have been updated to use the
SpectacularAPIView.
Fixed the typo in the name of PerformanceData
@moijes12
Copy link
Contributor Author

moijes12 commented Jan 15, 2026

@gmierz

I was able to fix the issue. django-filter recommends usage of drf-spectacular for generating schemas with DRF (see). The schema generation methods of the DRF related DjangoFilterBackend were deprecated in django-filter version 23.0. I have updated the DEFAULT_SCHEMA_CLASS and the updated the views.

As part of my latest change, I have:

  • Reverted my previous commit
  • Added drf_spectacular to the requirements
  • Updated settings.py to use drf_spectacular in the installed apps as well as for REST schema generation
  • Updated the /webapp/api/urls.py to use drf_spectacular.views.SpectacularAPIView for schema
  • Updated the RedocApp component's specUrl to point to ?format=json as drf_spectacular cannot use ?format=openapi-json
  • Updated typos as done previously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants