Skip to content

Add typing to inform spectacular of field details#920

Open
AlanCoding wants to merge 1 commit intoansible:develfrom
AlanCoding:better_typing
Open

Add typing to inform spectacular of field details#920
AlanCoding wants to merge 1 commit intoansible:develfrom
AlanCoding:better_typing

Conversation

@AlanCoding
Copy link
Copy Markdown
Member

@AlanCoding AlanCoding commented Jan 16, 2026

Description

Working on #919

Saw

/home/arominge/repos/django-ansible-base/ansible_base/rbac/api/serializers.py:341: Warning [UserAccessAssignmentViewSet > UserAccessAssignmentSerializer]: unable to resolve type hint for function "get_intermediary_roles". Consider using a type hint or @extend_schema_field. Defaulting to string.

for later sanity

$ python manage.py spectacular 2>&1 | grep 'UserAccessAssignmentViewSet' | wc -l
4

after this change the warning goes away. And to wrap this up:

$ python manage.py spectacular 2>&1 | grep 'UserAccessAssignmentViewSet' | wc -l
3

formally addresses 1 warning. How many are left? For posterity:

$ python manage.py spectacular 2>&1 | wc -l
18718

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test update
  • Refactoring (no functional changes)
  • Development environment change
  • Configuration change

Self-Review Checklist

  • I have performed a self-review of my code
  • I have added relevant comments to complex code sections
  • I have updated documentation where needed
  • I have considered the security impact of these changes
  • I have considered performance implications
  • I have thought about error handling and edge cases
  • I have tested the changes in my local environment

Note

Adds explicit typing to RBAC serializers to aid drf-spectacular and remove a schema warning.

  • Introduces TypedDict types RoleDefinitionSummary and AssignmentSummary in serializers.py
  • Annotates return types for helpers like summarize_role_definition, summarize_assignment_list, and get_object_role_assignments
  • Adds typed SerializerMethodFields for object_role_assignments and intermediary_roles
  • Types get_intermediary_roles(self, assignment: RoleUserAssignment) -> list[AssignmentSummary], addressing the prior unresolved type hint warning

Written by Cursor Bugbot for commit 6d7747e. This will update automatically on new commits. Configure here.

@jewzaam
Copy link
Copy Markdown

jewzaam commented Jan 16, 2026

From the PR description:

$ python manage.py spectacular 2>&1 | wc -l
18718

But this output includes debug and the generated openapi spec. In the output it summarizes findings.

Schema generation summary:
Warnings: 221 (78 unique)
Errors:   32 (8 unique)

The bulk of the warnings are for missing OpenApiAuthenticationExtension for test-app that could be ignored. So yes there are things that could be fixed but it's not 20k things.

@github-actions
Copy link
Copy Markdown

DVCS PR Check Results:

Could not find JIRA key(s) in PR title, branch name, or commit messages

@sonarqubecloud
Copy link
Copy Markdown

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.

2 participants