Skip to content

Commit b6eea56

Browse files
authored
Merge branch 'main' into trainer-update-deps
2 parents 32ae13b + 340284f commit b6eea56

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

medcat-trainer/docker-compose-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ services:
2525
environment:
2626
- MCT_VERSION=latest
2727
# OIDC Settings
28-
- USE_OIDC=1
28+
- USE_OIDC=0
2929
- KEYCLOAK_URL=http://keycloak.cogstack.localhost
3030
- KEYCLOAK_REALM=cogstack-realm
3131
- KEYCLOAK_FRONTEND_CLIENT_ID=cogstack-medcattrainer-frontend

medcat-trainer/docs/installation.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ Environment variables are used to configure the app:
7878
|EMAIL_PASS|The password or authentication key which will be used with the email address|
7979
|EMAIL_HOST|The hostname of the SMTP server which will be used to send email (default: mail.cogstack.org)|
8080
|EMAIL_PORT|The port that the SMTP server is listening to, common numbers are 25, 465, 587 (default: 465)|
81+
|MCTRAINER_BOOTSTRAP_ADMIN_USERNAME|Username for the default admin user created on initial startup (default: admin)|
82+
|MCTRAINER_BOOTSTRAP_ADMIN_EMAIL|Email address for the default admin user created on initial startup (default: admin@example.com)|
83+
|MCTRAINER_BOOTSTRAP_ADMIN_PASSWORD|Password for the default admin user created on initial startup (default: admin)|
8184

8285
Set these and re-run the docker-compose file.
8386

medcat-trainer/webapp/api/api/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ def save(self, *args, skip_load=False, **kwargs):
136136
super().save(*args, **kwargs)
137137
else:
138138
# For new objects, just update the FK fields without full save
139-
# Fixes psycopg.errors.UniqueViolation: duplicate key value violates unique constraint "api_modelpack_pkey"
139+
# Remove force_insert if present and set force_update to ensure Django treats this as an update
140+
# Removing the kwarg fixes error "Cannot force both insert and updating in model saving."
141+
# Setting update_fields fixes errorpsycopg.errors.UniqueViolation: duplicate key value violates unique constraint "api_modelpack_pkey"
142+
kwargs.pop('force_insert', None)
143+
kwargs['force_update'] = True
140144
super().save(*args, update_fields=['concept_db', 'vocab'], **kwargs)
141145

142146
def __str__(self):

medcat-trainer/webapp/scripts/run.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ uv run python /home/api/manage.py migrate api --noinput
2121
# Generates the runtime configuration for the web app and copies it to the static directory for web access
2222
/home/scripts/nginx-entrypoint.sh
2323

24-
# create a new super user, with username and password 'admin'
24+
# create a new super user, with configurable username, email, and password via env vars
2525
# also create a user group `user_group` that prevents users from deleting models
26-
echo "from django.contrib.auth import get_user_model
26+
echo "import os
27+
from django.contrib.auth import get_user_model
2728
User = get_user_model()
28-
if not User.objects.filter(username='admin').exists():
29-
User.objects.create_superuser('admin', 'admin@example.com', 'admin')
30-
" | (cd /home/api && uv run python manage.py shell)
29+
admin_username = os.getenv('MCTRAINER_BOOTSTRAP_ADMIN_USERNAME') or 'admin'
30+
admin_email = os.getenv('MCTRAINER_BOOTSTRAP_ADMIN_EMAIL') or 'admin@example.com'
31+
admin_password = os.getenv('MCTRAINER_BOOTSTRAP_ADMIN_PASSWORD') or 'admin'
32+
if not User.objects.filter(username=admin_username).exists():
33+
User.objects.create_superuser(admin_username, admin_email, admin_password)
34+
" | python manage.py shell
3135

3236
if [ $LOAD_EXAMPLES ]; then
3337
echo "Loading examples..."

0 commit comments

Comments
 (0)