From 8566e19b550ce72827352c1a3f946e304a88be75 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Wed, 13 Mar 2024 13:06:48 -0700 Subject: [PATCH 1/2] Add pre-commit hook and documentation to prevent swappable model dependencies for auth from being committed. --- .pre-commit-config.yaml | 5 +++++ docs/backend_architecture/upgrade.rst | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f3edf8877c..9a613b60d34 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -64,6 +64,11 @@ repos: kolibri/core/logger/migrations/0003_auto_20170531_1140\.py| kolibri/core/logger/migrations/0005_auto_20180514_1419\.py| )$ + - id: no-swappable-auth-migrations + name: No migrations with swappable auth models (settings.AUTH_USER_MODEL) + entry: settings\.AUTH_USER_MODEL + language: pygrep + files: migrations/.*\.py$ - repo: https://github.com/isidentical/teyit rev: 0.4.3 hooks: diff --git a/docs/backend_architecture/upgrade.rst b/docs/backend_architecture/upgrade.rst index 4ba7e2c07fd..9db73a5e6cb 100644 --- a/docs/backend_architecture/upgrade.rst +++ b/docs/backend_architecture/upgrade.rst @@ -20,6 +20,12 @@ that take a ``choices`` keyword argument, where the choices are strings. The strings should have no prefix (``u`` or ``b``) and the migration should contain ``from __future__ import unicode_literals`` as an import. +For any migrations involving Foreign keys to the FacilityUser model, the migration +will automatically be generated to use a swappable dependency on settings.AUTH_USER_MODEL. +This should be changed to remove the swappable dependency, set a fixed migration dependency +and remove the AUTH_USER_MODEL setting from the settings file. FacilityUser should be used +instead. + We also use the upgrade functionality triggered during the CLI initialization to copy in new copies of static files that are used in the frontend app. These upgrades are only triggered for a subset of our CLI commands - start, From a12f7cdf46f0f49902ac878e57eac743d40a9ae8 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Thu, 4 Apr 2024 14:10:07 -0700 Subject: [PATCH 2/2] Clarify guidance for preventing swappable migrations. --- docs/backend_architecture/upgrade.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/backend_architecture/upgrade.rst b/docs/backend_architecture/upgrade.rst index 9db73a5e6cb..1a044e73738 100644 --- a/docs/backend_architecture/upgrade.rst +++ b/docs/backend_architecture/upgrade.rst @@ -21,10 +21,10 @@ strings should have no prefix (``u`` or ``b``) and the migration should contain ``from __future__ import unicode_literals`` as an import. For any migrations involving Foreign keys to the FacilityUser model, the migration -will automatically be generated to use a swappable dependency on settings.AUTH_USER_MODEL. -This should be changed to remove the swappable dependency, set a fixed migration dependency -and remove the AUTH_USER_MODEL setting from the settings file. FacilityUser should be used -instead. +will automatically be generated by Django to use a swappable dependency on settings.AUTH_USER_MODEL. +This should be updated by removing the swappable dependency, setting a fixed migration dependency +and replacing the reference to `settings.AUTH_USER_MODEL` with `"kolibriauth.FacilityUser"` +instead. For an example of this, see this previous pull request: https://github.com/learningequality/kolibri/pull/11984 . We also use the upgrade functionality triggered during the CLI initialization to copy in new copies of static files that are used in the frontend