Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typing necessary to satisfy eda-server OpenAPI issues #276

Merged
merged 3 commits into from
Apr 8, 2024

Conversation

AlanCoding
Copy link
Member

This fixes problems that I encountered on the eda-server RBAC branch using the OpenAPI generator, when rendering the openapi.json endpoint.

For these things, it complains that it doesn't know what type to use. It hasn't stopped complaining. Here are some that still remain, limited to DAB content:

/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/lib/routers/association_resource_router.py: Warning [RelatedRoleTeamAssignmentViewSet]: could not derive type of path parameter "team_assignments" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:team_assignments>) or annotating the parameter type with @extend_schema. Defaulting to "string".
/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/lib/routers/association_resource_router.py: Warning [RelatedRoleUserAssignmentViewSet]: could not derive type of path parameter "user_assignments" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:user_assignments>) or annotating the parameter type with @extend_schema. Defaulting to "string".
/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/rbac/api/views.py: Warning [RoleTeamAssignmentViewSet]: could not derive type of path parameter "id" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:id>) or annotating the parameter type with @extend_schema. Defaulting to "string".
/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/rbac/api/views.py: Warning [RoleUserAssignmentViewSet]: could not derive type of path parameter "id" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:id>) or annotating the parameter type with @extend_schema. Defaulting to "string".
/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/resource_registry/views.py: Error [ServiceIndexRootView]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'super' object has no attribute 'get_serializer_class')
/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/resource_registry/views.py: Error [ServiceMetadataView]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'super' object has no attribute 'get_serializer_class')
/home/alancoding/repos/awx/testing/django-ansible-base/ansible_base/resource_registry/views.py: Error [ValidateLocalUserView]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'super' object has no attribute 'get_serializer_class')
2024-04-05 21:20:09,160 django.channels.server INFO     HTTP GET /api/eda/v1/openapi.json 200 [0.17, 127.0.0.1:44884]

But the much larger list of issues is knocked down by these changes.

The generated client also somewhat needs this to be right, and this matters most for the related endpoint pk parameter which it could not identify as an integer before. So that in specific is likely to fix a bug their QE hasn't gotten far enough to hit yet.

Type hints are quite nice for this, in that it avoids us having to add the dependency and decorate all our views, and I really don't want to do that.

@AlanCoding AlanCoding added the Ready for review This PR is ready for review either initially or comments have been address label Apr 6, 2024
Copy link
Member

@Dostonbek1 Dostonbek1 left a comment

Choose a reason for hiding this comment

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

I tested the changes in this PR in combination with the PR on eda-server and confirmed that it resolves the outstanding warnings related to dab_rbac library. The only remaining warnings are related to resource_registry (and one native to eda-server), which I'm not sure if it falls in the scope of this PR. Remaining warnings for ref:

eda-api-1                | /app/src/src/aap_eda/api/serializers/rulebook.py: Warning [AuditRuleViewSet > AuditEventSerializer]: could not resolve serializer field "YAMLSerializerField(allow_null=True, help_text='The payload in the event', required=False)". Defaulting to "string"
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/lib/routers/association_resource_router.py: Warning [RelatedRoleTeamAssignmentViewSet]: could not derive type of path parameter "team_assignments" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:team_assignments>) or annotating the parameter type with @extend_schema. Defaulting to "string".
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/lib/routers/association_resource_router.py: Warning [RelatedRoleUserAssignmentViewSet]: could not derive type of path parameter "user_assignments" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:user_assignments>) or annotating the parameter type with @extend_schema. Defaulting to "string".
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/resource_registry/views.py: Error [ServiceIndexRootView]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'super' object has no attribute 'get_serializer_class')
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/resource_registry/views.py: Error [ServiceMetadataView]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'super' object has no attribute 'get_serializer_class')
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/resource_registry/serializers.py: Warning [ResourceTypeViewSet > ResourceTypeSerializer]: unable to resolve type hint for function "get_url". Consider using a type hint or @extend_schema_field. Defaulting to string.
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/resource_registry/serializers.py: Warning [ResourceViewSet > ResourceListSerializer]: unable to resolve type hint for function "get_url". Consider using a type hint or @extend_schema_field. Defaulting to string.
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/resource_registry/serializers.py: Warning [ResourceViewSet > ResourceSerializer]: unable to resolve type hint for function "get_url". Consider using a type hint or @extend_schema_field. Defaulting to string.
eda-api-1                | /app/venv/lib64/python3.11/site-packages/ansible_base/resource_registry/views.py: Error [ValidateLocalUserView]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'super' object has no attribute 'get_serializer_class')

@AlanCoding
Copy link
Member Author

Oh this isn't good:

Exception: 'super' object has no attribute 'get_serializer_class'

I'll push a fix for that (in the eda-server PR).

I thought some others would be resolved like:

unable to resolve type hint for function "get_url".

I'll have one more quick look, because I thought those were fixed.

@AlanCoding
Copy link
Member Author

unable to resolve type hint for function "get_url".

It seems this is because of the 2 potential return types. I'm not sure if we can convert the return value to string? Would that be okay?

@AlanCoding
Copy link
Member Author

I filed #283 for the resource registry endpoints.

Copy link

sonarcloud bot commented Apr 8, 2024

@AlanCoding AlanCoding merged commit e51dd9b into ansible:devel Apr 8, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review This PR is ready for review either initially or comments have been address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants