Bug 1928549: Fix API schema generation and 500 error on docs page#9148
Bug 1928549: Fix API schema generation and 500 error on docs page#9148Archaeopteryx merged 5 commits intomozilla:masterfrom
Conversation
|
@bhearsum Please can you review this if you get some time |
|
I'm not actually a reviewer for Treeherder.... @Archaeopteryx ? |
|
No problem. Thanks @bhearsum |
|
|
||
|
|
||
| class PerfomanceJobViewSet(viewsets.ReadOnlyModelViewSet): | ||
| class PerformanceJobViewSet(viewsets.ViewSet): |
There was a problem hiding this comment.
Thank you for fixing these typos while you were here :)
|
Hi @moijes12, thanks for looking into this! I see that there was a patch for django-filter that should have added the 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. |
|
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
…page" This reverts commit a3343f5.
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
|
I was able to fix the issue. As part of my latest change, I have:
|
| 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 |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@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
Archaeopteryx
left a comment
There was a problem hiding this comment.
Thank you for fixing this.
This PR resolves a 500 error encountered when accessing the
/docs/and/api/schema/endpoints. The issue was caused by incompatibilities betweendjango-filteranddjangorestframework's schema generation, as well as missing attributes in specific API views.TreeherderFilterBackendto implement missingget_schema_operation_parametersmethod inDjangoFilterBackend.DEFAULT_FILTER_BACKENDSandperformance_data.pyviewsets to use the new custom backend.PerformanceJobViewSetto inherit from ViewSet to avoidserializer_classassertion errors.AttributeErrorinPerfCompareResults.get_serializer_classwhen request isNoneduring schema generation.@jmaher @gmierz
Fixes Bug 1928549