diff --git a/pyproject.toml b/pyproject.toml index b3584b61d..cd214837c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -187,6 +187,35 @@ line-ending = "lf" select = [ "E4", "E7", "E9", "F" ] extend-select = [ "ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async + "B002", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B003", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B004", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B005", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B006", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B008", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B009", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B010", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B012", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B013", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B014", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B015", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B016", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B017", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B018", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B019", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B020", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B021", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B022", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B023", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B025", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B026", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B029", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B030", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B031", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B032", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B033", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B035", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "B039", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b "C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 "COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com "D419", # https://docs.astral.sh/ruff/rules/#pydocstyle-d diff --git a/src/documents/models.py b/src/documents/models.py index a4e608720..289eb4ccc 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -377,7 +377,7 @@ class Document(SoftDeleteModel, ModelWithOwner): # type: ignore[django-manager- from documents.versioning import versions_newest_first if hasattr(self, "effective_content"): - return getattr(self, "effective_content") + return self.effective_content if self.root_document_id is not None or self.pk is None: return self.content diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index ff407b5ca..d7b80744a 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1147,7 +1147,7 @@ class DocumentSerializer( def to_representation(self, instance): doc = super().to_representation(instance) if "content" in self.fields and hasattr(instance, "effective_content"): - doc["content"] = getattr(instance, "effective_content") or "" + doc["content"] = instance.effective_content or "" if self.truncate_content and "content" in self.fields: doc["content"] = doc.get("content")[0:550] return doc @@ -2922,7 +2922,7 @@ class ShareLinkBundleSerializer(OwnedObjectSerializer): return share_link_bundle def get_document_count(self, obj: ShareLinkBundle) -> int: - return getattr(obj, "document_total") or obj.documents.count() + return obj.document_total or obj.documents.count() class BulkEditObjectsSerializer(SerializerWithPerms, SetPermissionsMixin): diff --git a/src/documents/tests/test_bulk_edit.py b/src/documents/tests/test_bulk_edit.py index 6063a9bbc..a42b45f9a 100644 --- a/src/documents/tests/test_bulk_edit.py +++ b/src/documents/tests/test_bulk_edit.py @@ -777,7 +777,7 @@ class TestPDFActions(DirectoriesMixin, TestCase): sig.set.return_value.apply_async.side_effect = Exception("boom") mock_consume_file.return_value = sig - with self.assertRaises(Exception): + with self.assertRaises(Exception): # noqa: B017 - mock injects a bare Exception bulk_edit.merge(doc_ids, delete_originals=True) self.doc1.refresh_from_db() @@ -1318,7 +1318,7 @@ class TestPDFActions(DirectoriesMixin, TestCase): sig.apply_async.side_effect = Exception("boom") mock_chord.return_value = sig - with self.assertRaises(Exception): + with self.assertRaises(Exception): # noqa: B017 - mock injects a bare Exception bulk_edit.edit_pdf(doc_ids, operations, delete_original=True) self.doc2.refresh_from_db() @@ -1430,7 +1430,7 @@ class TestPDFActions(DirectoriesMixin, TestCase): {"page": 9999}, # invalid page, forces error during PDF load ] with self.assertLogs("paperless.bulk_edit", level="ERROR"): - with self.assertRaises(Exception): + with self.assertRaises(ValueError): bulk_edit.edit_pdf(doc_ids, operations) mock_group.assert_not_called() mock_consume_file.assert_not_called() diff --git a/src/documents/tests/test_classifier.py b/src/documents/tests/test_classifier.py index 133dc88fe..be26225e0 100644 --- a/src/documents/tests/test_classifier.py +++ b/src/documents/tests/test_classifier.py @@ -783,7 +783,7 @@ class TestClassifier(DirectoriesMixin, TestCase): Path(settings.MODEL_FILE).touch() mock_load.side_effect = Exception() - with self.assertRaises(Exception): + with self.assertRaises(Exception): # noqa: B017 - mock injects a bare Exception load_classifier(raise_exception=True) diff --git a/src/documents/tests/test_workflows.py b/src/documents/tests/test_workflows.py index 5c5ff548f..8c7bb0114 100644 --- a/src/documents/tests/test_workflows.py +++ b/src/documents/tests/test_workflows.py @@ -2851,7 +2851,7 @@ class TestWorkflows( doc = Document.objects.create( title="test", ) - self.assertRaises(Exception, document_matches_workflow, doc, w, 99) + self.assertRaises(Exception, document_matches_workflow, doc, w, 99) # noqa: B017 - raises a bare Exception for unsupported trigger types def test_removal_action_document_updated_workflow(self) -> None: """ diff --git a/src/paperless_ai/tests/test_ai_classifier.py b/src/paperless_ai/tests/test_ai_classifier.py index 6159f78b9..7de4370c5 100644 --- a/src/paperless_ai/tests/test_ai_classifier.py +++ b/src/paperless_ai/tests/test_ai_classifier.py @@ -167,7 +167,7 @@ def test_get_ai_document_classification_failure(mock_run_llm_query, mock_documen """ mock_run_llm_query.side_effect = Exception("LLM query failed") - with pytest.raises(Exception): + with pytest.raises(Exception): # noqa: B017 - mock injects a bare Exception get_ai_document_classification(mock_document) diff --git a/src/paperless_mail/tests/test_preprocessor.py b/src/paperless_mail/tests/test_preprocessor.py index 33c9b3839..581abb875 100644 --- a/src/paperless_mail/tests/test_preprocessor.py +++ b/src/paperless_mail/tests/test_preprocessor.py @@ -184,7 +184,7 @@ class TestMailMessageGpgDecryptor(TestMail): EMAIL_GNUPG_HOME=empty_gpg_home, ): message_decryptor = MailMessageDecryptor() - self.assertRaises(Exception, message_decryptor.run, encrypted_message) + self.assertRaises(Exception, message_decryptor.run, encrypted_message) # noqa: B017 - raises a bare Exception on decryption failure finally: # Clean up the temporary GPG home used only by this test try: