Skip to content

Raise FieldError instead of AssertionError for unresolved lookups in Q.check#70

Closed
SAY-5 wants to merge 1 commit intodropseed:masterfrom
SAY-5:fix/check-constraint-regex-choices-68
Closed

Raise FieldError instead of AssertionError for unresolved lookups in Q.check#70
SAY-5 wants to merge 1 commit intodropseed:masterfrom
SAY-5:fix/check-constraint-regex-choices-68

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 5, 2026

Fixes #68.

CheckConstraint.validate catches FieldError from Q.check() to skip client-side validation when the field map (against) is missing a field that the constraint's Q references. Query.solve_lookup_type was raising a bare AssertionError instead of FieldError when the Query has no model and no annotation matches the lookup, so the catch was bypassed and full_clean() crashed.

This happens in the issue's reproducer because full_clean() adds the field to exclude after clean_fields raises a choices ValidationError, then runs validate_constraints with the field absent from against.

Changing the assert to raise FieldError restores the intended fall-through and matches the historical Django behavior the existing except FieldError: pass was written for.

Includes a regression test that covers the excluded-field path.

…s in Q.check

When CheckConstraint.validate runs Q.check() with an instance whose
field map is missing a referenced field (for example after full_clean
excludes a field that already failed clean_fields), Query.solve_lookup_type
hit a bare assert and crashed with AssertionError. CheckConstraint.validate
catches FieldError to skip unresolvable client-side checks, so converting
the assert to FieldError restores that semantics.

Closes dropseed#68

Signed-off-by: SAY-5 <say.apm35@gmail.com>
@davegaeddert
Copy link
Copy Markdown
Member

A lot of this was rewritten and this issue has been fixed already. Thanks!

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.

CheckConstraint with __regex lookup + choices on the same field crashes full_clean with AssertionError

2 participants