Repository: pulp/pulpcore

Issue:
Fix import in wsgi preventing startup
**Version**
Confirmed with Katello folks using 3.49 branch.

**Describe the bug**
We're getting an error during the startup stage:
```python
Starting Pulp API Server...
Traceback (most recent call last):
  File "/usr/bin/pulpcore-api", line 33, in <module>
    sys.exit(load_entry_point('pulpcore==3.49.1', 'console_scripts', 'pulpcore-api')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pulpcore/app/entrypoint.py", line 140, in main
    PulpcoreApiApplication(options).run()
  File "/usr/lib/python3.11/site-packages/gunicorn/app/base.py", line 231, in run
    super().run()
  File "/usr/lib/python3.11/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
    ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/gunicorn/arbiter.py", line 58, in __init__
    self.setup(app)
  File "/usr/lib/python3.11/site-packages/gunicorn/arbiter.py", line 118, in setup
    self.app.wsgi()
  File "/usr/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
                    ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pulpcore/app/entrypoint.py", line 95, in load
    import pulpcore.app.wsgi
  File "/usr/lib/python3.11/site-packages/pulpcore/app/wsgi.py", line 14, in <module>
    from pulpcore.app.util import init_domain_metrics_exporter
  File "/usr/lib/python3.11/site-packages/pulpcore/app/util.py", line 24, in <module>
    from pulpcore.app import models
  File "/usr/lib/python3.11/site-packages/pulpcore/app/models/__init__.py", line 4, in <module>
    from .base import (
  File "/usr/lib/python3.11/site-packages/pulpcore/app/models/base.py", line 3, in <module>
    from django.contrib.contenttypes.fields import GenericRelation
  File "/usr/lib/python3.11/site-packages/django/contrib/contenttypes/fields.py", line 7, in <module>
    from django.contrib.contenttypes.models import ContentType
  File "/usr/lib/python3.11/site-packages/django/contrib/contenttypes/models.py", line 139, in <module>
    class ContentType(models.Model):
  File "/usr/lib/python3.11/site-packages/django/db/models/base.py", line 129, in __new__
    app_config = apps.get_containing_app_config(module)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/django/apps/registry.py", line 260, in get_containing_app_config
```

and what got our eye was this line:
```python
File "/usr/lib/python3.11/site-packages/pulpcore/app/wsgi.py", line 14, in <module>
    from pulpcore.app.util import init_domain_metrics_exporter
```

Also, there's already a fix for this in the main branch #5178

**To Reproduce**
Installing using pip and rpm packages.

**Expected behavior**
The application should start without issues



Discussion:

Resolving patch:
diff --git a/pulpcore/app/wsgi.py b/pulpcore/app/wsgi.py
--- a/pulpcore/app/wsgi.py
+++ b/pulpcore/app/wsgi.py
@@ -11,7 +11,6 @@
 from opentelemetry.instrumentation.wsgi import OpenTelemetryMiddleware
 
 from pulpcore.app.entrypoint import using_pulp_api_worker
-from pulpcore.app.util import init_domain_metrics_exporter
 
 if not using_pulp_api_worker.get(False):
     raise RuntimeError("This app must be executed using pulpcore-api entrypoint.")
@@ -19,4 +18,6 @@
 application = get_wsgi_application()
 application = OpenTelemetryMiddleware(application)
 
+from pulpcore.app.util import init_domain_metrics_exporter  # noqa: E402
+
 init_domain_metrics_exporter()


Test patch: