Skip to content

brands: fix migration 0008 by removing incorrect context manager usage#13635

Merged
BeryJu merged 1 commit intogoauthentik:mainfrom
dominic-r:sdko/fix-css-failing-migration
Mar 23, 2025
Merged

brands: fix migration 0008 by removing incorrect context manager usage#13635
BeryJu merged 1 commit intogoauthentik:mainfrom
dominic-r:sdko/fix-css-failing-migration

Conversation

@dominic-r
Copy link
Member

@dominic-r dominic-r commented Mar 22, 2025

The migration was incorrectly using Path.read_text() with a context manager,
which caused a TypeError. Fixed by directly reading the file content since
read_text() returns a string, not a context manager.

Error Log

worker-1      |   Applying authentik_brands.0008_brand_branding_custom_css...
server-1      | {"event":"backend not alive yet","level":"debug","logger":"authentik.router.unicorn","timestamp":"2025-03-22T18:17:19Z"}
worker-1      | {"domain_url": null, "event": "releasing database lock", "level": "info", "logger": "lifecycle.migrate", "pid": 7, "schema_name": "public", "timestamp": "2025-03-22T18:17:19.546815"}
worker-1      | Traceback (most recent call last):
worker-1      |   File "<frozen runpy>", line 198, in _run_module_as_main
worker-1      |   File "<frozen runpy>", line 88, in _run_code
worker-1      |   File "/manage.py", line 43, in <module>
worker-1      |     run_migrations()
worker-1      |   File "/lifecycle/migrate.py", line 115, in run_migrations
worker-1      |     execute_from_command_line(["", "migrate_schemas"])
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
worker-1      |     utility.execute()
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
worker-1      |     self.fetch_command(subcommand).run_from_argv(self.argv)
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
worker-1      |     self.execute(*args, **cmd_options)
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
worker-1      |     output = self.handle(*args, **options)
worker-1      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django_tenants/management/commands/migrate_schemas.py", line 63, in handle
worker-1      |     executor.run_migrations(tenants=[self.PUBLIC_SCHEMA_NAME])
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django_tenants/migration_executors/standard.py", line 11, in run_migrations
worker-1      |     run_migrations(self.args, self.options, self.codename, self.PUBLIC_SCHEMA_NAME)
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django_tenants/migration_executors/base.py", line 61, in run_migrations
worker-1      |     migrate_command_class(stdout=stdout, stderr=stderr).execute(*args, **options)
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
worker-1      |     output = self.handle(*args, **options)
worker-1      |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper
worker-1      |     res = handle_func(*args, **kwargs)
worker-1      |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 356, in handle
worker-1      |     post_migrate_state = executor.migrate(
worker-1      |                          ^^^^^^^^^^^^^^^^^
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 135, in migrate
worker-1      |     state = self._migrate_all_forwards(
worker-1      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
worker-1      |     state = self.apply_migration(
worker-1      |             ^^^^^^^^^^^^^^^^^^^^^
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
worker-1      |     state = migration.apply(state, schema_editor)
worker-1      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/db/migrations/migration.py", line 132, in apply
worker-1      |     operation.database_forwards(
worker-1      |   File "/ak-root/.venv/lib/python3.12/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
worker-1      |     self.code(from_state.apps, schema_editor)
worker-1      |   File "/authentik/brands/migrations/0008_brand_branding_custom_css.py", line 18, in migrate_custom_css
worker-1      |     with path.read_text() as css:
worker-1      |          ^^^^^^^^^^^^^^^^
worker-1      | TypeError: 'str' object does not support the context manager protocol
worker-1 exited with code 1

Tested-On: HEAD at 3eccef8

Details

REPLACE ME


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

@dominic-r dominic-r requested a review from a team as a code owner March 22, 2025 18:23
@dominic-r
Copy link
Member Author

cc @BeryJu

@netlify
Copy link

netlify bot commented Mar 22, 2025

Deploy Preview for authentik-docs canceled.

Name Link
🔨 Latest commit 82e1aaa
🔍 Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/67df001be160980008aaa36c

@netlify
Copy link

netlify bot commented Mar 22, 2025

Deploy Preview for authentik-storybook canceled.

Name Link
🔨 Latest commit 82e1aaa
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/67df001ba9ae1e00082c873c

@codecov
Copy link

codecov bot commented Mar 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.75%. Comparing base (3eccef8) to head (82e1aaa).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13635   +/-   ##
=======================================
  Coverage   92.75%   92.75%           
=======================================
  Files         794      794           
  Lines       40508    40508           
=======================================
+ Hits        37572    37575    +3     
+ Misses       2936     2933    -3     
Flag Coverage Δ
e2e 48.01% <ø> (+0.04%) ⬆️
integration 24.30% <ø> (ø)
unit 90.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@BeryJu BeryJu changed the title core: brands: fix migration 0008 by removing incorrect context manager usage brands: fix migration 0008 by removing incorrect context manager usage Mar 23, 2025
@BeryJu BeryJu merged commit 1b588b9 into goauthentik:main Mar 23, 2025
88 checks passed
@dominic-r dominic-r deleted the sdko/fix-css-failing-migration branch March 23, 2025 19:42
kensternberg-authentik added a commit that referenced this pull request Apr 25, 2025
* main: (76 commits)
  admin: fix system API when using bearer token (#13651)
  website: bump the build group in /website with 6 updates (#13645)
  core: bump goauthentik.io/api/v3 from 3.2025022.5 to 3.2025022.6 (#13646)
  translate: Updates for file web/xliff/en.xlf in fr (#13653)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in fr (#13652)
  website/integrations: add tandoor (#13560)
  core, web: update translations (#13642)
  providers/scim: fix group membership check failing (#13644)
  ci: add semgrep (#13643)
  flows: fix API not returning configured background (#13641)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh_CN (#13631)
  translate: Updates for file locale/en/LC_MESSAGES/django.po in zh-Hans (#13633)
  translate: Updates for file web/xliff/en.xlf in zh_CN (#13632)
  translate: Updates for file web/xliff/en.xlf in zh-Hans (#13634)
  brands: fix migration 0008 by removing incorrect context manager usage (#13635)
  web: Fix prop. (#13630)
  core, web: update translations (#13628)
  web/admin: reworked sync status card (#13625)
  core: bump github.com/golang-jwt/jwt/v5 from 5.2.1 to 5.2.2 (#13626)
  translate: Updates for file web/xliff/en.xlf in zh-Hans (#13622)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants