Remove eager DB access in proxy AppConfig.ready()#14121
Conversation
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @Copilot on file. In order for us to review and merge your code, please contact the project maintainers to get yourself added. |
…alization Agent-Logs-Url: https://github.com/GeoNode/geonode/sessions/6036f356-560b-4347-8a98-b5fff9c0bccb Co-authored-by: etj <717359+etj@users.noreply.github.com>
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @Copilot on file. In order for us to review and merge your code, please contact the project maintainers to get yourself added. |
Agent-Logs-Url: https://github.com/GeoNode/geonode/sessions/6036f356-560b-4347-8a98-b5fff9c0bccb Co-authored-by: etj <717359+etj@users.noreply.github.com>
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @Copilot on file. In order for us to review and merge your code, please contact the project maintainers to get yourself added. |
There was a problem hiding this comment.
Pull request overview
This PR removes eager database access from geonode.proxy app initialization by stopping the proxy registry from being populated during AppConfig.ready(), and instead wiring Link model signals so the registry can initialize lazily on first use.
Changes:
- Remove startup-time registry initialization (and its post-migrate fallback) from
GeoNodeProxyAppConfig.ready(). - Move
Linkpost-save/post-delete signal wiring intoGeoNodeProxyAppConfig.ready()to avoid DB access at boot. - Simplify
ProxyUrlsRegistry.initialize()by removing first-init signal-connection logic and the unused signals import.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
geonode/proxy/apps.py |
Stops eager registry initialization and connects Link model signals in ready(). |
geonode/proxy/utils.py |
Removes first-init flag/signal wiring from initialize() to support lazy initialization. |
Comments suppressed due to low confidence (1)
geonode/proxy/utils.py:20
- With eager registry.initialize() removed from AppConfig.ready(), the post_save handler can run before ProxyUrlsRegistry.initialize() has ever been called. In that case proxy_urls_registry.proxy_allowed_hosts is not defined (it’s only created inside initialize()/set()/clear()), so link_post_save() -> register_host() will raise AttributeError the first time a qualifying Link is saved (same risk for any other signal handlers calling register_host). Consider initializing proxy_allowed_hosts to an empty set (or the base allowed hosts) in the registry constructor/class, or making register_host lazily create the set when missing.
class ProxyUrlsRegistry:
_last_registry_load = None
_registry_reload_threshold = getattr(settings, "PROXY_RELOAD_REGISTRY_THRESHOLD_DAYS", 1)
def initialize(self):
from geonode.base.models import Link
from geonode.geoserver.helpers import ogc_server_settings
self.proxy_allowed_hosts = set([site_url.hostname] + list(getattr(settings, "PROXY_ALLOWED_HOSTS", ())))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @Copilot on file. In order for us to review and merge your code, please contact the project maintainers to get yourself added. |
geonode.proxywas callingproxy_urls_registry.initialize()insideAppConfig.ready(), triggering a DB query at startup and causing Django to emit aRuntimeWarningabout database access during app initialization.The registry already supports lazy initialization —
get_proxy_allowed_hosts()re-initializes automatically when the cache is empty or stale — so there's no need to eagerly populate it at boot.Changes
geonode/proxy/apps.py: Removerun_setup_hooks()and itstry/exceptwrapper. WireLinkpost-save/post-delete signal handlers directly inready()(no DB access required).geonode/proxy/utils.py: Remove_first_initflag and signal-connection code frominitialize()— signals are now owned byAppConfig.ready(). Drop the unusedsignalsimport.