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

Changes in 0.15.x to use kolibri with external plugins #9543

Merged
merged 3 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions kolibri/core/bookmarks/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Migration(migrations.Migration):

dependencies = [
("kolibriauth", "0019_collection_no_mptt"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
migrations.swappable_dependency("kolibriauth.FacilityUser"),
Copy link
Member

Choose a reason for hiding this comment

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

Oh wow, it's Django doing this - in the model specification it's explicitly targeting the FacilityUser model, but it went ahead and turned it into this reference anyway: https://github.com/learningequality/kolibri/blob/develop/kolibri/core/bookmarks/models.py#L18

]

operations = [
Expand Down Expand Up @@ -57,7 +57,7 @@ class Migration(migrations.Migration):
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
],
Expand Down
4 changes: 2 additions & 2 deletions kolibri/core/device/migrations/0012_syncqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
migrations.swappable_dependency("kolibriauth.FacilityUser"),
("device", "0011_devicesettings_subset_of_users_device"),
]

Expand All @@ -36,7 +36,7 @@ class Migration(migrations.Migration):
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
],
Expand Down
4 changes: 2 additions & 2 deletions kolibri/core/device/migrations/0013_usersyncstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Migration(migrations.Migration):

dependencies = [
("morango", "0016_store_deserialization_error"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
migrations.swappable_dependency("kolibriauth.FacilityUser"),
("device", "0012_syncqueue"),
]

Expand Down Expand Up @@ -43,7 +43,7 @@ class Migration(migrations.Migration):
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
],
Expand Down
4 changes: 2 additions & 2 deletions kolibri/core/exams/migrations/0005_individualsyncableexam.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Migration(migrations.Migration):

dependencies = [
("kolibriauth", "0019_collection_no_mptt"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
migrations.swappable_dependency("kolibriauth.FacilityUser"),
("exams", "0004_exam_add_dates_opened_created_and_archived"),
]

Expand Down Expand Up @@ -58,7 +58,7 @@ class Migration(migrations.Migration):
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Migration(migrations.Migration):
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="exams",
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
migrations.AlterField(
Expand All @@ -32,7 +32,7 @@ class Migration(migrations.Migration):
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="assigned_exams",
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Migration(migrations.Migration):

dependencies = [
("kolibriauth", "0019_collection_no_mptt"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
migrations.swappable_dependency("kolibriauth.FacilityUser"),
("lessons", "0002_auto_20180221_1115"),
]

Expand Down Expand Up @@ -58,7 +58,7 @@ class Migration(migrations.Migration):
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Migration(migrations.Migration):
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="lessons_created",
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
migrations.AlterField(
Expand All @@ -32,7 +32,7 @@ class Migration(migrations.Migration):
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="assigned_lessons",
to=settings.AUTH_USER_MODEL,
to="kolibriauth.FacilityUser",
),
),
]
4 changes: 4 additions & 0 deletions kolibri/utils/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ def _post_django_initialization():
settings.CACHES["process_cache"]["TIMEOUT"],
**settings.CACHES["process_cache"]["OPTIONS"]
)
except AttributeError:
Copy link
Member

Choose a reason for hiding this comment

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

I guess the other way of handling this would be to check if the process_cache is not the default cache - which in the case of Redis it is, and I assume for online instances also?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand this comment. If process_cache is in CACHES (i.e. it's not the default cache) it means we're not using redis.
The logic would be mostly the same. We can remove the attribute error checking the cache BACKEND. Is that what you have in mind? :


def _post_django_initialization():
    from kolibri.deployment.default.cache import CACHES

    if 'process_cache' in CACHES:
        backend = CACHES['process_cache']['BACKEND']
        if backend != 'django.core.cache.backends.db.DatabaseCache':
            try:
                process_cache.cull()
            except SQLite3DatabaseError:
                shutil.rmtree(process_cache.directory, ignore_errors=True)
                os.mkdir(process_cache.directory)
                process_cache._cache = FanoutCache(
                    process_cache.directory,
                    settings.CACHES["process_cache"]["SHARDS"],
                    settings.CACHES["process_cache"]["TIMEOUT"],
                    **settings.CACHES["process_cache"]["OPTIONS"]
                )


Copy link
Member

Choose a reason for hiding this comment

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

Yeah, mostly just to make it based on Django settings, rather than our OPTIONS, so in the case that it's overridden by a custom settings file, we're still checking properly.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, done it. I have also added a guard in kolibri/core/device/migrations/0003_contentcachekey.py to avoid the problems this migration had when running in a system using DatabaseCache.

# DatabaseCache, no actions needed supposing
# kolibri manage createcachetable has been executed previously
pass


def _upgrades_after_django_setup(updated, version):
Expand Down