Skip to content

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

Merged
merged 4 commits into from
Jun 11, 2025

Conversation

youtux
Copy link
Contributor

@youtux youtux commented Jun 11, 2025

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

youtux and others added 3 commits June 11, 2025 10:49
`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]: ...
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good one, reverted

Copy link
Contributor

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: ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 9c19640

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thanks!

@sobolevn sobolevn merged commit 13a2f99 into typeddjango:master Jun 11, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants