Skip to content

Commit b2fe258

Browse files
authored
Fix: do not access CheckConstraint.check on django >=5.1 (#40)
1 parent fc37cca commit b2fe258

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/extra_checks/checks/model_field_checks.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,15 @@ def apply(
295295
field_choices.append("")
296296
in_name = f"{field.name}__in"
297297
for constraint in model._meta.constraints:
298-
if isinstance(constraint, models.CheckConstraint) and isinstance(
299-
constraint.check, models.Q
300-
):
301-
for entry in constraint.check.children:
298+
if isinstance(constraint, models.CheckConstraint):
299+
condition = (
300+
constraint.check
301+
if django.VERSION < (5, 1)
302+
else constraint.condition
303+
)
304+
if not isinstance(condition, models.Q):
305+
continue
306+
for entry in condition.children:
302307
if (
303308
isinstance(entry, tuple)
304309
and entry[0] == in_name

0 commit comments

Comments
 (0)