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

App/Container is failing to start with v2024.10 #11895

Open
vish9812 opened this issue Nov 3, 2024 · 1 comment
Open

App/Container is failing to start with v2024.10 #11895

vish9812 opened this issue Nov 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@vish9812
Copy link

vish9812 commented Nov 3, 2024

Describe the bug
The app is failing to start.

To Reproduce
Steps to reproduce the behavior:

  1. Change version to v2024.10 from v2024.8 in the .env file
  2. Pull new image
  3. Restart the container

Expected behavior
App/Container starts successfully without any errors.

Logs
I'm getting the following errors:

Error 1

authentik_worker  | Running migrations:
authentik_worker  |   Applying authentik_core.0040_provider_invalidation_flow...
authentik_db      | 2024-11-01 18:37:38.953 UTC [44] ERROR:  duplicate key value violates unique constraint "django_migrations_pkey"
authentik_db      | 2024-11-01 18:37:38.953 UTC [44] DETAIL:  Key (id)=(497) already exists.

Error 2
column "invalidation_flow_id" of relation "authentik_core_provider" already exists

authentik_worker  | Running migrations:
authentik_worker  |   Applying authentik_core.0040_provider_invalidation_flow...
authentik_db      | 2024-11-01 18:16:28.043 UTC [87] ERROR:  column "invalidation_flow_id" of relation "authentik_core_provider" already exists
authentik_db      | 2024-11-01 18:16:28.043 UTC [87] STATEMENT:  ALTER TABLE "authentik_core_provider" ADD COLUMN "invalidation_flow_id" uuid NULL CONSTRAINT "authentik_core_provi_invalidation_flow_id_69c4fd1b_fk_authentik" REFERENCES "authentik_flows_flow"("flow_uuid") DEFERRABLE INITIALLY DEFERRED; SET CONSTRAINTS "authentik_core_provi_invalidation_flow_id_69c4fd1b_fk_authentik" IMMEDIATE
authentik_worker  | {"domain_url": null, "event": "releasing database lock", "level": "info", "logger": "lifecycle.migrate", "pid": 7, "schema_name": "public", "timestamp": "2024-11-01T18:16:28.043831"}
authentik_server  | 2024-11-01 18:16:28 [info     ] applying django migrations
authentik_worker  | Traceback (most recent call last):
authentik_worker  |   File "/ak-root/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
authentik_worker  |     return self.cursor.execute(sql)
authentik_worker  |            ^^^^^^^^^^^^^^^^^^^^^^^^
authentik_worker  |   File "/ak-root/venv/lib/python3.12/site-packages/django_prometheus/db/common.py", line 69, in execute
authentik_worker  |     return super().execute(*args, **kwargs)
authentik_worker  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
authentik_worker  |   File "/ak-root/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute
authentik_worker  |     raise ex.with_traceback(None)
authentik_worker  | psycopg.errors.DuplicateColumn: column "invalidation_flow_id" of relation "authentik_core_provider" already exists

Version and Deployment (please complete the following information):

  • authentik version: 2024.10
  • Deployment: docker-compose
@MichaelSp
Copy link

As a hacky workaround I replaced the /authentik/core/migrations/0040_provider_invalidation_flow.py just for one startup with this content:

# Generated by Django 5.0.9 on 2024-10-02 11:35
      
import django.db.models.deletion
from django.apps.registry import Apps
from django.db import migrations, models, connection
from django.db.backends.base.schema import BaseDatabaseSchemaEditor


def migrate_invalidation_flow_default(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
    from authentik.flows.models import FlowDesignation, FlowAuthenticationRequirement
    
    db_alias = schema_editor.connection.alias
    
    Flow = apps.get_model("authentik_flows", "Flow")
    Provider = apps.get_model("authentik_core", "Provider")
    
    # So this flow is managed via a blueprint, bue we're in a migration so we don't want to rely on that
    # since the blueprint is just an empty flow we can just create it here
    # and let it be managed by the blueprint later
    flow, _ = Flow.objects.using(db_alias).update_or_create(
        slug="default-provider-invalidation-flow",
        defaults={
            "name": "Logged out of application",
            "title": "You've logged out of %(app)s.",
            "authentication": FlowAuthenticationRequirement.NONE,
            "designation": FlowDesignation.INVALIDATION,
        },
    )
    Provider.objects.using(db_alias).filter(invalidation_flow=None).update(invalidation_flow=flow)


def add_invalidation_flow_column(apps, schema_editor):
    
    
    with connection.cursor() as cursor:
        cursor.execute("""
    SELECT column_name
    FROM information_schema.columns
    WHERE table_name='authentik_core_provider' AND column_name='invalidation_flow_id';
    """)
        if not cursor.fetchone():
            migrations.AddField(
                model_name="provider",
                name="invalidation_flow",
                field=models.ForeignKey(
                    default=None,
                    help_text="Flow used ending the session from a provider.",
                    null=True,
                    on_delete=django.db.models.deletion.SET_DEFAULT,
                    related_name="provider_invalidation",
                    to="authentik_flows.flow",
                ),
            ).database_forwards(apps, schema_editor)


class Migration(migrations.Migration):
    
    
    dependencies = [
        ("authentik_core", "0039_source_group_matching_mode_alter_group_name_and_more"),
        ("authentik_flows", "0027_auto_20231028_1424"),
    ]

operations = [
    migrations.RunPython(add_invalidation_flow_column),
    migrations.RunPython(migrate_invalidation_flow_default),
]

This allowed me to run the migrations once. On next startup the migration will not be retried again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants