Repository: pulp/pulpcore

Issue:
Compression monkeypatch is not always being loaded

**Describe the bug**

For whatever reason, the monkeypatch added in https://github.com/pulp/pulpcore/pull/3884 is not always loaded.  I'm not 100% sure if it has to do with the order in which the files are loaded into the interpreter or some other detail, but we need to make it reliable.

**To Reproduce**

This patch
```diff
diff --git a/pulpcore/app/monkeypatch.py b/pulpcore/app/monkeypatch.py
index 38852f6a7..94ec14fb6 100644
--- a/pulpcore/app/monkeypatch.py
+++ b/pulpcore/app/monkeypatch.py
@@ -49,6 +49,8 @@ if sys.version_info.major == 3 and sys.version_info.minor < 12:
         _Stream is intended to be used only internally.
         """
 
+        is_patched = True
+
         def _init_write_gz(self):
             """Initialize for writing with gzip compression."""
             self.cmp = self.zlib.compressobj(
diff --git a/pulpcore/app/tasks/export.py b/pulpcore/app/tasks/export.py
index 3259187d9..c013d0283 100644
--- a/pulpcore/app/tasks/export.py
+++ b/pulpcore/app/tasks/export.py
@@ -191,6 +191,9 @@ def fs_publication_export(exporter_pk, publication_pk, start_repo_version_pk=Non
         exporter_pk (str): FilesystemExporter pk
         publication_pk (str): Publication pk
     """
+    if not hasattr(tarfile._Stream, "is_patched"):
+        raise RuntimeError("tarfile module was not patched properly")
+
     exporter = Exporter.objects.get(pk=exporter_pk).cast()
     publication = Publication.objects.get(pk=publication_pk).cast()
 
@@ -235,6 +238,9 @@ def fs_repo_version_export(exporter_pk, repo_version_pk, start_repo_version_pk=N
         exporter_pk (str): FilesystemExporter pk
         repo_version_pk (str): RepositoryVersion pk
     """
+    if not hasattr(tarfile._Stream, "is_patched"):
+        raise RuntimeError("tarfile module was not patched properly")
+
     exporter = Exporter.objects.get(pk=exporter_pk).cast()
     repo_version = RepositoryVersion.objects.get(pk=repo_version_pk)
     start_repo_version = None
@@ -387,6 +393,9 @@ def pulp_export(exporter_pk, params):
     the_export.validated_start_versions = serializer.validated_data.get("start_versions", None)
     the_export.validated_chunk_size = serializer.validated_data.get("chunk_size", None)
 
+    if not hasattr(tarfile._Stream, "is_patched"):
+        raise RuntimeError("tarfile module was not patched properly")
+
     try:
         the_export.task = Task.current()
 

```


**Expected behavior**
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.  Please provide links to any previous discussions via Discourse or Bugzilla.



Discussion:

Resolving patch:
diff --git a/pulpcore/app/tasks/export.py b/pulpcore/app/tasks/export.py
--- a/pulpcore/app/tasks/export.py
+++ b/pulpcore/app/tasks/export.py
@@ -5,6 +5,7 @@
 import os.path
 import subprocess
 import tarfile
+
 from distutils.util import strtobool
 from gettext import gettext as _
 from glob import glob
@@ -26,6 +27,9 @@
 )
 from pulpcore.app.models.content import ContentArtifact
 from pulpcore.app.serializers import PulpExportSerializer
+
+# ensure the compression patch is loaded
+from pulpcore.app import monkeypatch  # noqa
 from pulpcore.app.util import get_version_from_model
 from pulpcore.app.importexport import (
     export_versions,


Test patch: