Skip to content

Remove eager DB access in proxy AppConfig.ready()#14121

Merged
giohappy merged 4 commits into
masterfrom
copilot/fix-proxy-warning-at-boot-time
May 15, 2026
Merged

Remove eager DB access in proxy AppConfig.ready()#14121
giohappy merged 4 commits into
masterfrom
copilot/fix-proxy-warning-at-boot-time

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

geonode.proxy was calling proxy_urls_registry.initialize() inside AppConfig.ready(), triggering a DB query at startup and causing Django to emit a RuntimeWarning about 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: Remove run_setup_hooks() and its try/except wrapper. Wire Link post-save/post-delete signal handlers directly in ready() (no DB access required).
  • geonode/proxy/utils.py: Remove _first_init flag and signal-connection code from initialize() — signals are now owned by AppConfig.ready(). Drop the unused signals import.
# Before: DB hit at every startup
def ready(self):
    super().ready()
    try:
        proxy_urls_registry.initialize()  # queries DB
    except Exception:
        post_migrate.connect(run_setup_hooks, sender=self)

# After: no DB access; signals wired cleanly; registry initializes lazily on first use
def ready(self):
    super().ready()
    from geonode.base.models import Link
    signals.post_save.connect(link_post_save, sender=Link)
    signals.post_delete.connect(link_post_delete, sender=Link)

Copilot AI assigned Copilot and etj Apr 9, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 9, 2026

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.

Copilot AI linked an issue Apr 9, 2026 that may be closed by this pull request
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 9, 2026

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.

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 9, 2026

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.

Copilot AI changed the title [WIP] Fix proxy warning during app initialization Remove eager DB access in proxy AppConfig.ready() Apr 9, 2026
Copilot AI requested a review from etj April 9, 2026 17:10
Copilot finished work on behalf of etj April 9, 2026 17:10
@etj etj marked this pull request as ready for review May 12, 2026 16:38
@etj etj requested review from Copilot and giohappy May 12, 2026 16:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Link post-save/post-delete signal wiring into GeoNodeProxyAppConfig.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.

Comment thread geonode/proxy/apps.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 15, 2026

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.

@giohappy giohappy merged commit f260139 into master May 15, 2026
15 of 16 checks passed
@giohappy giohappy deleted the copilot/fix-proxy-warning-at-boot-time branch May 15, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy warning at boot time

4 participants