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 async queryset for Django 4.1 #1131

Merged
merged 3 commits into from
Aug 28, 2022
Merged

Add async queryset for Django 4.1 #1131

merged 3 commits into from
Aug 28, 2022

Conversation

xncbf
Copy link
Contributor

@xncbf xncbf commented Aug 28, 2022

I have made things!

I added all of asynchronous queries created in django 4.1, including contains created in django 4.0.

Related issues

n/a

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.

This is ok as the first step, but please: take in mind that we also have special handling of .filter and other query set methods in out plugin.

This would need to be addressed as well.

@sobolevn sobolevn merged commit d0a9793 into typeddjango:master Aug 28, 2022
Copy link
Contributor

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

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

damn I was just reviewing @sobolevn 😅 making a PR with these changes

Comment on lines +96 to +97
def contains(self, objs: Iterable[_T]) -> bool: ...
async def acontains(self, objs: Iterable[_T]) -> bool: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

this type is wrong - it doesn't take an iterable of type _T but a single instance of _T

https://docs.djangoproject.com/en/4.1/ref/models/querysets/#django.db.models.query.QuerySet.contains

Suggested change
def contains(self, objs: Iterable[_T]) -> bool: ...
async def acontains(self, objs: Iterable[_T]) -> bool: ...
def contains(self, obj: _T) -> bool: ...
async def acontains(self, obj: _T) -> bool: ...

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for catching this! I never used async django, so my knowledge is limited: I was just checking that signatures are the same as regular methods.

Comment on lines 65 to +70
def bulk_create(
self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ...
) -> List[_T]: ...
async def abulk_create(
self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ...
) -> List[_T]: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

Whilst modifying bulk_create let's also import the new Django 4.1 parameters.

https://docs.djangoproject.com/en/4.1/ref/models/querysets/#django.db.models.query.QuerySet.bulk_create

The update_conflicts, update_fields, and unique_fields parameters were added to support updating fields when a row insertion fails on conflict.

Suggested change
def bulk_create(
self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ...
) -> List[_T]: ...
async def abulk_create(
self, objs: Iterable[_T], batch_size: Optional[int] = ..., ignore_conflicts: bool = ...
) -> List[_T]: ...
def bulk_create(
self,
objs: Iterable[_T],
batch_size: Optional[int] = ...,
ignore_conflicts: bool = ...,
update_conflicts: bool = ...,
update_fields: Optional[Collection[str]] = ...,
unique_fields: Optional[Collection[str]] = ...,
) -> List[_T]: ...
async def abulk_create(
self,
objs: Iterable[_T],
batch_size: Optional[int] = ...,
ignore_conflicts: bool = ...,
update_conflicts: bool = ...,
update_fields: Optional[Collection[str]] = ...,
unique_fields: Optional[Collection[str]] = ...,
) -> List[_T]: ...

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