field-choices-constraint fails on complex CheckConstraint
Closed this issue · 1 comments
stefanofusai commented
Hello!
I'm trying out this package, everything works correctly but I'm getting this error when trying out the field-choices-constraint
:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
self.run()
File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1010, in run
self._target(*self._args, **self._kwargs)
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/django/core/management/commands/runserver.py", line 133, in inner_run
self.check(display_num_errors=True)
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 486, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/django/core/checks/registry.py", line 94, in run_checks
errors.extend(new_errors)
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/extra_checks/checks/model_checks.py", line 67, in check_models
yield from check(field, ast=field_ast, model=model)
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/extra_checks/checks/model_field_checks.py", line 32, in __call__
yield from super().__call__(obj, ast=ast, **kwargs)
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/extra_checks/checks/base_checks.py", line 53, in __call__
for error in self.apply(obj, ast=ast, **kwargs):
File "/Users/stefano/Desktop/watchanalytics/source/api/.venv/lib/python3.12/site-packages/extra_checks/checks/model_field_checks.py", line 299, in apply
conditions = dict(constraint.check.children) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot convert dictionary update sequence element #1 to a sequence
This is the repr of constraint.check.children
: [('url', None), <Q: (AND: (OR: ('url__startswith', 'http://'), ('url__startswith', 'https://')), ('url__length__lte', 2000))>]
and this is the code of the CheckConstraint
:
CheckConstraint(
check=(
Q(url=None)
| (
(Q(url__startswith="http://") | Q(url__startswith="https://"))
& Q(url__length__lte=2000)
)
)
)
Am I doing something wrong?
Thanks for the help
kalekseev commented