Skip to content

Bug 1928549: Fix API schema generation and 500 error on docs page#9148

Merged
Archaeopteryx merged 5 commits intomozilla:masterfrom
moijes12:bug1998273
Jan 26, 2026
Merged

Bug 1928549: Fix API schema generation and 500 error on docs page#9148
Archaeopteryx merged 5 commits intomozilla:masterfrom
moijes12:bug1998273

Conversation

@moijes12
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

moijes12 commented Jan 6, 2026

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

@bhearsum
Copy link
Copy Markdown
Collaborator

bhearsum commented Jan 6, 2026

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

@moijes12
Copy link
Copy Markdown
Contributor Author

moijes12 commented Jan 6, 2026

No problem. Thanks @bhearsum



class PerfomanceJobViewSet(viewsets.ReadOnlyModelViewSet):
class PerformanceJobViewSet(viewsets.ViewSet):
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown
Collaborator

@gmierz gmierz left a comment

Choose a reason for hiding this comment

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

Thanks for looking into that @moijes12! Just one comment below :)

Comment thread requirements/common.in Outdated
jsonschema==4.25.1 # import jsonschema
djangorestframework==3.16.1 # Imported as rest_framework
django-cors-headers==4.9.0 # Listed as 3rd party app on settings.py
drf_spectacular==0.29.0 # Used for REST API Schema Generation
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@moijes12 can you use drf-spectacular here instead with the - instead of the _? It seems like the _ is from an old package name and they are using - for it now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gmierz Thanks for pointing that out. I have fixed that in the latest commit.

* Corrected the name of drf-spectacular in the common.in
* Regenerated the common.txt
Copy link
Copy Markdown
Collaborator

@gmierz gmierz left a comment

Choose a reason for hiding this comment

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

r+, looks great to me now and locally it's all working well :)

Thanks for taking care of this @moijes12!

Copy link
Copy Markdown
Collaborator

@Archaeopteryx Archaeopteryx left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this.

@Archaeopteryx Archaeopteryx merged commit 9cd7f76 into mozilla:master Jan 26, 2026
6 checks passed
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.

4 participants