Kani999 / netbox-attachments

Plugin to manage attachments for any model
Apache License 2.0
55 stars 4 forks source link

APPS_NOT_READY_WARNING_MSG #67

Closed llamafilm closed 1 month ago

llamafilm commented 1 month ago

Since installing this plugin, I am seeing this warning often in the logs.

/opt/netbox-4.0.7/venv/lib/python3.12/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConf>
  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)

This is 100% repeatable every time I run systemctl restart netbox.service, and it also happens at some other times. If I disable this plugin in configuration.py then the warnings stop.

The Django docs suggest this is caused by accessing the database during AppConfig.ready() but I can't tell where in the code this is happening. For debugging, I enabled postgres log_statement and captured the attached logs during the netbox service restart. Without this plugin, there are 4 queries. With this plugin enabled, there are 704 queries!

without attachments.log with attachments.log

Kani999 commented 1 month ago

I've also noticed the warning but haven't been able to identify the problem yet. Thank you for the logs; they will be very helpful. I will look into this issue soon.

Kani999 commented 1 month ago

I believe the problem is located here: https://github.com/Kani999/netbox-attachments/blob/main/netbox_attachments/template_content.py#L128 during the initialization of the plugin for models.

Kani999 commented 1 month ago

@llamafilm could you try to install branch 67-apps_not_ready_warning_msg. I think it's fixed.

llamafilm commented 1 month ago

Thanks. I tested that branch and the warning is gone. Looks OK to me.