Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return
assert isinstance(node.left, Name)
assert isinstance(node.operator, Comparison)
assert isinstance(node.right, (Const, List))
# Check that field and value types are compatible
field = self.resolve_name(node.left)
value = node.right.value
if field is None:
if value is not None:
raise DjangoQLSchemaError(
'Related model %s can be compared to None only, but not to '
'%s' % (node.left.value, type(value).__name__)
)
else:
values = value if isinstance(node.right, List) else [value]
for v in values:
field.validate(v)
def validate(self, node):
"""
Validate DjangoQL AST tree vs. current schema
"""
assert isinstance(node, Node)
if isinstance(node.operator, Logical):
self.validate(node.left)
self.validate(node.right)
return
assert isinstance(node.left, Name)
assert isinstance(node.operator, Comparison)
assert isinstance(node.right, (Const, List))
# Check that field and value types are compatible
field = self.resolve_name(node.left)
value = node.right.value
if field is None:
if value is not None:
raise DjangoQLSchemaError(
'Related model %s can be compared to None only, but not to '
'%s' % (node.left.value, type(value).__name__)
)
else:
values = value if isinstance(node.right, List) else [value]
for v in values:
field.validate(v)