-
Notifications
You must be signed in to change notification settings - Fork 122
Add delete_many
to support for bulk deletes
#305
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
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6053ccb
Add support for bulk deletes
dvora-h ca2d4a4
linters
dvora-h ba7d552
linters
dvora-h ee80f7c
fix review comments
dvora-h d43b044
update more-itertools version
dvora-h cbba7ad
poetry fix - maybe?
chayim bb64339
Merge branch 'main' into bulk-delete
dvora-h c6a2591
Merge branch 'main' into bulk-delete
dvora-h 79fb4e3
merge main & add more-itertools 8.14.0
dvora-h 36c40b2
Merge branch 'bulk-delete' of https://github.com/redis/redis-om-pytho…
dvora-h 2cbe292
update poetry.lock
dvora-h f065194
linters
dvora-h b3f034b
fix test
dvora-h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
Migrator, | ||
QueryNotSupportedError, | ||
RedisModelError, | ||
NotFoundError | ||
) | ||
|
||
# We need to run this check as sync code (during tests) even in async mode | ||
|
@@ -552,6 +553,33 @@ async def test_saves_many(m): | |
assert await m.Member.get(pk=member2.pk) == member2 | ||
|
||
|
||
@py_test_mark_asyncio | ||
async def test_delete_many(m): | ||
member1 = m.Member( | ||
first_name="Andrew", | ||
last_name="Brookins", | ||
email="[email protected]", | ||
join_date=today, | ||
age=38, | ||
bio="This is the user bio.", | ||
) | ||
member2 = m.Member( | ||
first_name="Kim", | ||
last_name="Brookins", | ||
email="[email protected]", | ||
join_date=today, | ||
age=34, | ||
bio="This is the bio for Kim.", | ||
) | ||
members = [member1, member2] | ||
result = await m.Member.add(members) | ||
assert result == [member1, member2] | ||
result = await m.Member.delete_all(members) | ||
assert result == 2 | ||
with pytest.raises(NotFoundError): | ||
await m.Member.get(pk=member1.pk) | ||
|
||
|
||
@py_test_mark_asyncio | ||
async def test_updates_a_model(members, m): | ||
member1, member2, member3 = members | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,6 +297,59 @@ async def test_saves_many_explicit_transaction(address, m): | |
assert await m.Member.get(pk=member2.pk) == member2 | ||
|
||
|
||
@py_test_mark_asyncio | ||
async def test_delete_many_implicit_pipeline(address, m): | ||
member1 = m.Member( | ||
first_name="Andrew", | ||
last_name="Brookins", | ||
email="[email protected]", | ||
join_date=today, | ||
address=address, | ||
age=38, | ||
) | ||
member2 = m.Member( | ||
first_name="Kim", | ||
last_name="Brookins", | ||
email="[email protected]", | ||
join_date=today, | ||
address=address, | ||
age=34, | ||
) | ||
members = [member1, member2] | ||
result = await m.Member.add(members) | ||
assert result == [member1, member2] | ||
result = await m.Member.delete_all(members) | ||
assert result == 2 | ||
with pytest.raises(NotFoundError): | ||
await m.Member.get(pk=member2.pk) | ||
|
||
|
||
@py_test_mark_asyncio | ||
async def test_delete_many_explicit_transaction(address, m): | ||
member1 = m.Member( | ||
first_name="Andrew", | ||
last_name="Brookins", | ||
email="[email protected]", | ||
join_date=today, | ||
address=address, | ||
age=38, | ||
) | ||
member2 = m.Member( | ||
first_name="Kim", | ||
last_name="Brookins", | ||
email="[email protected]", | ||
join_date=today, | ||
address=address, | ||
age=34, | ||
) | ||
members = [member1, member2] | ||
result = await m.Member.add(members) | ||
assert result == [member1, member2] | ||
async with m.Member.db().pipeline(transaction=True) as pipeline: | ||
await m.Member.delete_all(members, pipeline=pipeline) | ||
assert await pipeline.execute() == [1, 1] | ||
|
||
|
||
async def save(members): | ||
for m in members: | ||
await m.save() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think delete_all and delete should call a new function named
_delete
underneath, that accepts a kwargs (at least). This would be a bit cleaner.