mirror of https://github.com/zulip/zulip.git
python: Update tuple handling pattern; returned by a delete() query.
This commit updates the pattern for dealing with tuples returned by the delete() query. The '(num_deleted, ignored) = ModelName.objects.filter().delete()' pattern is preferred due to better readability. We avoid the pattern '(num_deleted, _)' because Django uses _ for translation, which may lead to future bugs.
This commit is contained in:
parent
83423bb45b
commit
e45623fccc
|
@ -322,14 +322,14 @@ def delete_messages(msg_ids: List[int]) -> None:
|
|||
|
||||
|
||||
def delete_expired_attachments(realm: Realm) -> None:
|
||||
attachments_deleted, _ = Attachment.objects.filter(
|
||||
(num_deleted, ignored) = Attachment.objects.filter(
|
||||
messages__isnull=True,
|
||||
realm_id=realm.id,
|
||||
id__in=ArchivedAttachment.objects.filter(realm_id=realm.id),
|
||||
).delete()
|
||||
|
||||
if attachments_deleted > 0:
|
||||
logger.info("Cleaned up %s attachments for realm %s", attachments_deleted, realm.string_id)
|
||||
if num_deleted > 0:
|
||||
logger.info("Cleaned up %s attachments for realm %s", num_deleted, realm.string_id)
|
||||
|
||||
|
||||
def move_related_objects_to_archive(msg_ids: List[int]) -> None:
|
||||
|
|
|
@ -194,10 +194,10 @@ def unregister_remote_push_device(
|
|||
validate_bouncer_token_request(token, token_kind)
|
||||
user_identity = UserPushIdentityCompat(user_id=user_id, user_uuid=user_uuid)
|
||||
|
||||
deleted = RemotePushDeviceToken.objects.filter(
|
||||
(num_deleted, ignored) = RemotePushDeviceToken.objects.filter(
|
||||
user_identity.filter_q(), token=token, kind=token_kind, server=server
|
||||
).delete()
|
||||
if deleted[0] == 0:
|
||||
if num_deleted == 0:
|
||||
raise JsonableError(err_("Token does not exist"))
|
||||
|
||||
return json_success(request)
|
||||
|
|
Loading…
Reference in New Issue