Skip to content

Extending a view class with an operation ID does not cause a system check error #702

@Lucidiot

Description

@Lucidiot

Describe the bug

Using @extend_schema on an view class with an operation_id results in an error being displayed on almost every manage.py command, yet the deploy check does not show any error, neither does a request on a SchemaView. This makes the issue undetectable in a CI job.

To Reproduce

Create an APIView class that uses @extend_schema with an operation_id, and make sure that it is imported somewhere that gets loaded early on, such as a urls.py:

# views.py
@extend_schema(operation_id='OhSnap')
class InfuriatingAPIView(RetrieveAPIView):
    ...
# urls.py
from leproject.leapp import views

You can then run manage.py check --deploy:

λ ./manage.py check --deploy
Error #0: using @extend_schema on viewset class InfuriatingAPIView with parameters operation_id or operation will most likely result in a broken schema.
System check identified no issues (0 silenced).

Some inspection using a traceback.print_stack() in GeneratorStats.emit shows that the error occurs while Django runs other system checks related to the ROOT_URLCONF; the views are imported too early for the check to work. Maybe the views need to be somehow reimported?

Expected behavior

The deploy check should show an actual warning:

λ ./manage.py check --deploy
System check identified some issues:

WARNINGS:
?: (drf_spectacular.W002) using @extend_schema on viewset class InfuriatingAPIView with parameters operation_id or operation will most likely result in a broken schema.

System check identified 1 issue (0 silenced).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfix confirmation pendingissue has been fixed and confirmation from issue reporter is pending

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions