Bug: Slack Workspace model fails during Django initialization
- Dominant language
- Python
- Stars
- 451
- Forks
- 707
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 91
Description
Community & Support: [[LinkedIn Group](https://www.linkedin.com/groups/14656108/)](https://www.linkedin.com/groups/14656108/) · [[Slack #project-nest](https://owasp.slack.com/archives/project-nest)](https://owasp.slack.com/archives/project-nest)
Active project leaders: Arkadii Yakovets -- [[GitHub](https://github.com/arkid15r/)](https://github.com/arkid15r/) · [[LinkedIn](https://www.linkedin.com/in/arkid15r/)](https://www.linkedin.com/in/arkid15r/) · [[Slack](https://owasp.slack.com/team/U060W3NKLTF)](https://owasp.slack.com/team/U060W3NKLTF); Kate Golovanova -- [[GitHub](https://github.com/kasya/)](https://github.com/kasya/) · [[LinkedIn](https://www.linkedin.com/in/kate-golovanova/)](https://www.linkedin.com/in/kate-golovanova/) · [[Slack](https://owasp.slack.com/team/U07PWB1JZ6Z)](https://owasp.slack.com/team/U07PWB1JZ6Z)
[[Contributing](https://github.com/owasp/nest/blob/main/CONTRIBUTING.md)](https://github.com/owasp/nest/blob/main/CONTRIBUTING.md) · [[Code of Conduct](https://github.com/owasp/nest/blob/main/CODE_OF_CONDUCT.md)](https://github.com/owasp/nest/blob/main/CODE_OF_CONDUCT.md) · [[GSoC Mentors](https://github.com/owasp/nest/blob/main/MENTORS.md)](https://github.com/owasp/nest/blob/main/MENTORS.md)
---
## **Describe the bug**
Running the Django system check fails due to a model initialization issue in the Slack module. The error occurs because the `Workspace` model is imported before Django finishes registering applications.
---
## **To Reproduce**
Steps to reproduce the behavior:
1. Clone the repository
2. Install dependencies using Poetry
3. Set required environment variables
4. Run:
```
poetry run python manage.py check
```
5. Observe the error during Django initialization
---
## **Expected behavior**
Django should initialize successfully and `manage.py check` should complete without errors when all apps are correctly configured.
---
## **Are you going to work on fixing this?**
* [x] Yes
* [ ] No
---
## **Screenshots**
Attach:
## **Desktop (please complete the following information):**
* OS: Windows 11
* Browser: N/A
* Version: N/A
---
## **Smartphone (please complete the following information):**
* Device: N/A
* OS: N/A
* Browser: N/A
* Version: N/A
---
## **Additional context**
The issue is caused by early import of Slack models inside admin modules.
File:
```
apps/owasp/admin/mixins.py
```
Problematic import:
```python
from apps.slack.models.conversation import Conversation
```
This triggers model loading during Django admin autodiscovery, before the application registry is fully initialized, leading to:
```
RuntimeError: Model class apps.slack.models.workspace.Workspace
doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
```
Suggested fix:
Move the import inside functions or methods to delay model loading until after Django initialization.
Example:
```python
def get_conversation_model():
from apps.slack.models.conversation import Conversation
return Conversation
```
This avoids premature model import and resolves the issue.
Contributor guide
Assessment
This issue has not been assessed yet.