Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
upload: Remove useless warning.
Alex Vandiverea1b68fe3ff5
diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.pyindex 7c0ae2070d9..f8ee097229c 100644--- a/zerver/lib/upload/local.py+++ b/zerver/lib/upload/local.py@@ -1,4 +1,3 @@-import loggingimport osimport randomimport secrets@@ -53,21 +52,20 @@ def delete_local_file(type: Literal["avatars", "files"], path: str) -> bool:file_path = os.path.join(assert_is_not_none(settings.LOCAL_UPLOADS_DIR), type, path)assert_is_local_storage_path(type, file_path)- if os.path.isfile(file_path):- os.remove(file_path)-- # Remove as many directories up the tree as are now empty- directory = os.path.dirname(file_path)- while directory != settings.LOCAL_UPLOADS_DIR:- try:- os.rmdir(directory)- directory = os.path.dirname(directory)- except OSError:- break- return True- file_name = path.split("/")[-1]- logging.warning("%s does not exist. Its entry in the database will be removed.", file_name)- return False+ if not os.path.isfile(file_path):+ return False++ os.remove(file_path)++ # Remove as many directories up the tree as are now empty+ directory = os.path.dirname(file_path)+ while directory != settings.LOCAL_UPLOADS_DIR:+ try:+ os.rmdir(directory)+ directory = os.path.dirname(directory)+ except OSError:+ break+ return Trueclass LocalUploadBackend(ZulipUploadBackend):diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.pyindex b6b6bd61635..8fe2bf3de4b 100644--- a/zerver/lib/upload/s3.py+++ b/zerver/lib/upload/s3.py@@ -1,4 +1,3 @@-import loggingimport osimport secretsfrom collections.abc import Callable, Iterator@@ -176,11 +175,8 @@ class S3UploadBackend(ZulipUploadBackend):try:key.load()except botocore.exceptions.ClientError:- file_name = path_id.split("/")[-1]- logging.warning(- "%s does not exist. Its entry in the database will be removed.", file_name- )return False+key.delete()return Truediff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.pyindex 627f0bcac5d..b3415aeb013 100644--- a/zerver/tests/test_realm.py+++ b/zerver/tests/test_realm.py@@ -3021,8 +3021,7 @@ class ScrubRealmTest(ZulipTestCase):self.assertNotEqual(CustomProfileField.objects.filter(realm=zulip).count(), 0)- with self.assertLogs(level="WARNING"):- do_scrub_realm(zulip, acting_user=None)+ do_scrub_realm(zulip, acting_user=None)self.assertEqual(Message.objects.filter(diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex c36ab5cd321..0b5ba86e070 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -245,8 +245,7 @@ class DeactivationNoticeTestCase(ZulipTestCase):realm.refresh_from_db()assert realm.deactivatedassert realm.deactivated_redirect is None- with self.assertLogs(level="WARNING"):- do_scrub_realm(realm, acting_user=None)+ do_scrub_realm(realm, acting_user=None)result = self.client_get("/login/", follow=True)self.assertEqual(result.redirect_chain[-1], ("/accounts/deactivated/", 302))diff --git a/zerver/tests/test_tusd.py b/zerver/tests/test_tusd.pyindex 57ba30de607..622aff20432 100644--- a/zerver/tests/test_tusd.py+++ b/zerver/tests/test_tusd.py@@ -322,18 +322,12 @@ class TusdPreCreateTest(ZulipTestCase):confirmation_key = find_key_by_email(email)assert confirmation_key is not None- with self.assertLogs(level="WARNING") as warn_log:- result = self.client_post(- "/api/internal/tusd",- self.request(key=confirmation_key).model_dump(),- content_type="application/json",- )- self.assertEqual(result.status_code, 200)- # Verify if we tried to remove any existing upload.- self.assertEqual(- warn_log.output,- ["WARNING:root:slack.zip does not exist. Its entry in the database will be removed."],+ result = self.client_post(+ "/api/internal/tusd",+ self.request(key=confirmation_key).model_dump(),+ content_type="application/json",)+ self.assertEqual(result.status_code, 200)result_json = result.json()self.assertEqual(result_json.get("HttpResponse", None), None)self.assertEqual(result_json.get("RejectUpload", False), False)diff --git a/zerver/tests/test_upload_local.py b/zerver/tests/test_upload_local.pyindex b67fc713f14..c6d6998b997 100644--- a/zerver/tests/test_upload_local.py+++ b/zerver/tests/test_upload_local.py@@ -282,11 +282,6 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):self.assertEqual(expected_url, url)# Delete the tarball.- with self.assertLogs(level="WARNING") as warn_log:- self.assertIsNone(delete_export_tarball("/not_a_file"))- self.assertEqual(- warn_log.output,- ["WARNING:root:not_a_file does not exist. Its entry in the database will be removed."],- )+ self.assertIsNone(delete_export_tarball("/not_a_file"))path_id = urlsplit(url).pathself.assertEqual(delete_export_tarball(path_id), path_id)diff --git a/zerver/tests/test_upload_s3.py b/zerver/tests/test_upload_s3.pyindex cf60c6d5212..8a2445a16cb 100644--- a/zerver/tests/test_upload_s3.py+++ b/zerver/tests/test_upload_s3.py@@ -185,14 +185,7 @@ class S3Test(ZulipTestCase):bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0]with self.assertRaises(botocore.exceptions.ClientError):bucket.Object("non-existent-file").load()- with self.assertLogs(level="WARNING") as warn_log:- self.assertEqual(False, delete_message_attachment("non-existent-file"))- self.assertEqual(- warn_log.output,- [- "WARNING:root:non-existent-file does not exist. Its entry in the database will be removed."- ],- )+ self.assertEqual(False, delete_message_attachment("non-existent-file"))@use_s3_backenddef test_all_message_attachments(self) -> None:@@ -704,12 +697,7 @@ class S3Test(ZulipTestCase):self.assertIn("Expires", params)# Delete the tarball.- with self.assertLogs(level="WARNING") as warn_log:- self.assertIsNone(delete_export_tarball("/not_a_file"))- self.assertEqual(- warn_log.output,- ["WARNING:root:not_a_file does not exist. Its entry in the database will be removed."],- )+ self.assertIsNone(delete_export_tarball("/not_a_file"))self.assertEqual(delete_export_tarball(parsed_url.path), parsed_url.path)@override_settings(S3_EXPORT_BUCKET="")