tfranzel / drf-spectacular

Sane and flexible OpenAPI 3 schema generation for Django REST framework.
https://drf-spectacular.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.38k stars 264 forks source link

@extend_schema_view warnings do not result in failure with --fail-on-warn #706

Closed glennmatthews closed 2 years ago

glennmatthews commented 2 years ago

Describe the bug

Warnings emitted by https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/utils.py#L560 do not result in failure when spectacular is run with --fail-on-warn:

# nautobot-server spectacular --fail-on-warn --file /dev/null
Warning #0: @extend_schema_view argument "bulk_update" was not found on view IPAddressViewSet. method override for "bulk_update" will be ignored.
Warning #1: @extend_schema_view argument "bulk_partial_update" was not found on view IPAddressViewSet. method override for "bulk_partial_update" will be ignored.
# echo $?
0

Possibly a similar root cause to #702?

To Reproduce Use @extend_schema_view with a non-standard method name, such as:

@extend_schema_view(
    bulk_update=extend_schema(responses={"200": serializers.IPAddressSerializerLegacy(many=True)}, versions=["1.2"]),
    ...
)
class IPAddressViewSet(...)

(Note that in our specific case the warning is a bit spurious, see https://github.com/nautobot/nautobot/pull/1637 for how we are resolving the warning.)

Expected behavior When run with --fail-on-warn, any warning reported should cause a failure.

tfranzel commented 2 years ago

hey @glennmatthews, good catch! Took a moment to grasp the issue. The issue is that we have in total 2 warnings that are emitted during decoration time. You found one! Everything else is emitted during schema generation time. Since we clear the warning/error cache prior to generation, the message shows up in the console but is subsequently lost. Since its cleared there is no reason to raise anymore.

I'll try to figure out how to save those warnings. #702 is exactly the same issue provoked through another code path (check)

tfranzel commented 2 years ago

closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up.