Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distributed error reporting: Setting up the database that stores all the errors #12250

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
10 changes: 10 additions & 0 deletions kolibri/core/errorreports/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.apps import AppConfig


class KolibriErrorConfig(AppConfig):
name = "kolibri.core.errorreports"
label = "errorreports"
verbose_name = "Kolibri ErrorReports"

def ready(self):
Copy link
Member

Choose a reason for hiding this comment

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

There's probably no use case for this method. However if there is, then its worth changing its body from ... to pass that is more explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought both were the same thing!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to pass!

Copy link
Member

Choose a reason for hiding this comment

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

Pass is more explicit. ... could mean a host of things.
It goes back to my earlier question. Do we really need the ready method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not now, some apps inside core had it defined this way with pass. So I just copy-pasted

Copy link
Member

Choose a reason for hiding this comment

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

I thinks it's best we remove it as it won't really be necessary.

...
38 changes: 38 additions & 0 deletions kolibri/core/errorreports/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from kolibri.deployment.default.sqlite_db_names import ERROR_REPORTS


class ErrorReportsRouter(object):
"""
Determine how to route database calls for the ErrorReports app.
ref: https://docs.djangoproject.com/en/5.0/topics/db/multi-db/

"""

def db_for_read(self, model, **hints):
if model._meta.app_label == "errorreports":
return ERROR_REPORTS
return None

def db_for_write(self, model, **hints):
if model._meta.app_label == "errorreports":
return ERROR_REPORTS
return None

def allow_relation(self, obj1, obj2, **hints):
if (
obj1._meta.app_label == "errorreports"
and obj2._meta.app_label == "errorreports"
):
return True
elif "errorreports" not in [obj1._meta.app_label, obj2._meta.app_label]:
return None

return False

def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label == "errorreports":
return db == ERROR_REPORTS
elif db == ERROR_REPORTS:
return False

return None
2 changes: 2 additions & 0 deletions kolibri/deployment/default/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"kolibri.core.auth.apps.KolibriAuthConfig",
"kolibri.core.bookmarks",
"kolibri.core.content",
"kolibri.core.errorreports",
"kolibri.core.logger",
"kolibri.core.notifications.apps.KolibriNotificationsConfig",
"kolibri.core.tasks.apps.KolibriTasksConfig",
Expand Down Expand Up @@ -161,6 +162,7 @@
"kolibri.core.notifications.models.NotificationsRouter",
"kolibri.core.device.models.SyncQueueRouter",
"kolibri.core.discovery.models.NetworkLocationRouter",
"kolibri.core.errorreports.models.ErrorReportsRouter",
)

elif conf.OPTIONS["Database"]["DATABASE_ENGINE"] == "postgres":
Expand Down
9 changes: 8 additions & 1 deletion kolibri/deployment/default/sqlite_db_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@

NOTIFICATIONS = "notifications"

ERROR_REPORTS = "errorreports"

ADDITIONAL_SQLITE_DATABASES = (SYNC_QUEUE, NETWORK_LOCATION, NOTIFICATIONS)

ADDITIONAL_SQLITE_DATABASES = (
SYNC_QUEUE,
NETWORK_LOCATION,
NOTIFICATIONS,
ERROR_REPORTS,
)