Skip to content

Commit

Permalink
Add missing import, initialize missing variable (PR #132)
Browse files Browse the repository at this point in the history
- The exceptions module was used but not imported.
- The next_validator variable was not initialized in a certain code path, resulting in UnboundLocalErrors

---------

Co-authored-by: Bharat Chauhan <tell.bhch@gmail.com>
  • Loading branch information
nlsfnr and bhch authored Jan 9, 2024
1 parent c39494b commit 051d224
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion django_jsonform/models/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import json
from django.db import models
from django.core import exceptions
from django_jsonform.forms.fields import JSONFormField


Expand Down Expand Up @@ -95,4 +96,3 @@ def formfield(self, **kwargs):
'decoder': self.decoder,
**kwargs,
})

8 changes: 5 additions & 3 deletions django_jsonform/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def validate_array(self, schema, data, coords, *, raise_exc=False):
# TypeError is raised when trying to make a set from unashable types
# i.e. lists and dicts
# so we JSON-ify each item to make it a string
if len(data) != len(set([json.dumps(item) for item in data])):
if len(data) != len(set([json.dumps(item) for item in data])):
self.add_error(coords, 'All items in this list must be unique.', raise_exc=raise_exc)

if choices:
Expand All @@ -188,6 +188,7 @@ def validate_array(self, schema, data, coords, *, raise_exc=False):
next_schema = self.get_ref(next_schema['$ref'])

next_type = get_schema_type(next_schema)
next_validator = None

if next_type is None:
# property type isn't provided
Expand Down Expand Up @@ -261,6 +262,7 @@ def validate_object(self, schema, data, coords, raise_exc=False):
next_schema['required'] = True

next_type = get_schema_type(next_schema)
next_validator = None

if next_type is None:
# property type isn't provided
Expand Down Expand Up @@ -335,7 +337,7 @@ def validate_string(self, schema, data, coords, raise_exc=False):
elif format_ == 'date-time':
if not self.get_datetime(data):
self.add_error(coords, 'Enter a valid date and time.', raise_exc=raise_exc)

def validate_boolean(self, schema, data, coords, raise_exc=False):
if schema.get('required') and data is None:
self.add_error(coords, 'This field is required.', raise_exc=raise_exc)
Expand Down Expand Up @@ -429,7 +431,7 @@ def validate_oneOf(self, schema, data, coords, raise_exc=False):
matches_found += 1
# if matches_found > 1:
# break
#
#
# TODO: validate that one and only one subschema matches
# currently it's a bit hard to do, so we'll just match
# one item and don't care wheter more than one match
Expand Down

0 comments on commit 051d224

Please sign in to comment.