Closed bellini666 closed 1 month ago
This pull request fixes an issue where async fields could return non-awaitable values, potentially breaking functionality that expects awaitables. The change ensures that async fields always return an awaitable, addressing issue #639.
classDiagram
class AsyncPermission {
+async has_permission(source: Any, info: Info, **kwargs: Any) Union[bool, Awaitable[bool]]
}
class Query {
+list[Color] colors
}
class Color {
+strawberry.auto name
+list[Fruit] fruits
}
class Fruit {
+strawberry.auto name
}
Query --> Color : has
Color --> Fruit : has
Color --> AsyncPermission : uses
Fruit --> AsyncPermission : uses
Change | Details | Files |
---|---|---|
Modify the get_result function to always return an awaitable for async fields |
|
strawberry_django/fields/field.py |
Add comprehensive test cases for field permissions with async and sync scenarios |
|
tests/test_field_permissions.py |
Issue | Objective | Addressed | Explanation |
---|---|---|---|
#639 | Fix the 'object list can't be used in 'await' expression' error when using async has_permission with optimizer's enable_prefetch_related_optimization set to True |
✅ | |
#639 | Ensure async fields always return Awaitables | ✅ |
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 88.77%. Comparing base (
92c1221
) to head (ab3bbe3
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Async fields sometimes can return non-awaitable values, like when the optimizer is enabled and already prefetched the nested field.
This can break some places that expect an awaitable, like strawberry's base field permissions.
This change ensures that async fields always return an awaitable.
Fix #639
Summary by Sourcery
Fix async fields to consistently return awaitables, addressing issues with components expecting awaitable results, and add tests to validate this behavior.
Bug Fixes:
Tests: