Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not required ObjectProperty with a required field throws errors on instantiation #132

Open
KeithTsui opened this issue Mar 19, 2016 · 1 comment

Comments

@KeithTsui
Copy link

If I have something like this:

class A(JsonObject):
    field1 = StringProperty(required=True)

class B(JsonObject):
    a = ObjectProperty(A, default=None)

Then when I create an instance of B like b = B(), I will get an error:

Traceback (most recent call last):
  File "/Users/keith/molabs/movideo/tests/commons/api/views/test_mapper.py", line 160, in test_required
    b = B()
  File "/Users/keith/molabs/movideo/lib/jsonobject/base.py", line 229, in __init__
    d = value.default()
  File "/Users/keith/molabs/movideo/lib/jsonobject/properties.py", line 128, in <lambda>
    default = lambda self: self.item_type()
  File "/Users/keith/molabs/movideo/lib/jsonobject/base.py", line 232, in __init__
    self[key] = d
  File "/Users/keith/molabs/movideo/lib/jsonobject/base.py", line 296, in __setitem__
    wrapped, unwrapped = self.__unwrap(key, value)
  File "/Users/keith/molabs/movideo/lib/jsonobject/base.py", line 283, in __unwrap
    recursive=False,
  File "/Users/keith/molabs/movideo/lib/jsonobject/base_properties.py", line 113, in validate
    'Property {0} is required.'.format(self.name)
BadValueError: Property field1 is required.

If I set the default of the item to be None, it seems to work. Why shouldn't an object just have a default of None?

@raynaya
Copy link

raynaya commented Feb 15, 2018

This is a bug. If you have an object A which is optional and resides inside Object B. Then you cant have required fields inside A.

When A is not present inside B, it gives error for the scalar required properties of A. Should not be the case imo.

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

No branches or pull requests

2 participants