Skip to content

Skip user-condition validation when the auth table is missing#140

Open
arpitjain099 wants to merge 1 commit into
cfpb:mainfrom
arpitjain099:chore/validate-user-skip-when-table-missing
Open

Skip user-condition validation when the auth table is missing#140
arpitjain099 wants to merge 1 commit into
cfpb:mainfrom
arpitjain099:chore/validate-user-skip-when-table-missing

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #96.

validate_user does UserModel.objects.get(...). That validator runs inside the flag_conditions_check system check, which only catches ValidationError. On a fresh database the system checks run before the auth tables are created (for example during the first migrate), so the lookup raises OperationalError / ProgrammingError, and since the check does not catch it, the error propagates and aborts the migration. The maintainer confirmed this in the thread, and a commenter suggested catching the database error.

This catches OperationalError / ProgrammingError in validate_user and skips validation in that case. The username cannot be checked when its table does not exist yet, and it is validated normally once the tables are in place, so the only behavior change is that a missing table no longer breaks migrate. I went with skipping rather than raising a ValidationError, since raising would surface a misleading "invalid value" warning on every migrate when the value is actually fine.

Added test_user_table_missing_is_skipped, which mocks the manager lookup to raise each error and asserts validate_user does not raise. Full flags.tests.test_conditions_validators suite passes (13 tests).

validate_user queries the user table, and the system check that runs it
(flag_conditions_check) only catches ValidationError. On a fresh database
the system checks run before the auth tables exist (for example during the
first migrate), so the query raised OperationalError / ProgrammingError
and that error propagated out of the check and aborted the migration.

Catch those database errors in validate_user and skip validation in that
case; the username is still validated normally once the tables exist.

Fixes cfpb#96

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@willbarton willbarton self-requested a review June 15, 2026 11:41
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.

Setting user based flag conditions prevents migrations running on a fresh database

1 participant