-
-
Notifications
You must be signed in to change notification settings - Fork 487
Fix signature of LogEntryManager.log_actions
#2710
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
Conversation
`LogEntryManager.log_actions` can take any `Iterable[T]` for the `queryset` param, not necessarily a `QuerySet[T]`. Indeed, Django itself invokes it with a `list[T]` in `ModelAdmin.log_addition`: https://github.com/django/django/blob/091f66e51aa900f7d7650529621bdc8e4b0dee68/django/contrib/admin/options.py#L945
action_flag: int, | ||
change_message: str | list[Any] = "", | ||
*, | ||
single_object: bool = False, | ||
) -> list[LogEntry] | LogEntry: ... | ||
) -> list[LogEntry]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good one, reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use @overload
to be more specific about the return type:
@overload
def log_actions(
self,
user_id: int | str | UUID,
queryset: Iterable[Model],
action_flag: int,
change_message: str | list[Any] = "",
*,
single_object: Literal[True],
) -> LogEntry: ...
@overload
def log_actions(
self,
user_id: int | str | UUID,
queryset: Iterable[Model],
action_flag: int,
change_message: str | list[Any] = "",
*,
single_object: Literal[False] = False,
) -> list[LogEntry]: ...
@overload
def log_actions(
self,
user_id: int | str | UUID,
queryset: Iterable[Model],
action_flag: int,
change_message: str | list[Any] = "",
*,
single_object: bool = False,
) -> list[LogEntry] | LogEntry: ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 9c19640
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
LogEntryManager.log_actions
can take anyIterable[T]
for thequeryset
param, not necessarily aQuerySet[T]
. Indeed, Django itself invokes it with alist[T]
inModelAdmin.log_addition
: https://github.com/django/django/blob/091f66e51aa900f7d7650529621bdc8e4b0dee68/django/contrib/admin/options.py#L945