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

_allow_dynamic_properties = False raises bad error for nested schemas #105

Open
dannyroberts opened this issue Sep 30, 2014 · 1 comment

Comments

@dannyroberts
Copy link
Member

No description provided.

@majutsushi
Copy link

The description of this issue rather minimalist, but I'm running into this problem which may be the same issue:

class A(jsonobject.JsonObject):
    _allow_dynamic_properties = False

class B(A):
    foo = jsonobject.StringProperty(required=True)

class C(jsonobject.JsonObject):
    components = jsonobject.DictProperty(A, default={})

c = C()
c.components["test"] = (B(foo="/foo/bar"))
C(c.to_json())
Traceback (most recent call last):
  File "jsonobject/base.pyx", line 202, in jsonobject.jsonobject.base.JsonObjectBase.__init__
  File "jsonobject/base.pyx", line 239, in jsonobject.jsonobject.base.JsonObjectBase.set_raw_value
  File "jsonobject/base.pyx", line 322, in jsonobject.jsonobject.base.JsonObjectBase.__setattr__
AttributeError: 'foo' is not defined in schema (not a valid property)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "jsonobject/base.pyx", line 202, in jsonobject.jsonobject.base.JsonObjectBase.__init__
  File "jsonobject/base.pyx", line 235, in jsonobject.jsonobject.base.JsonObjectBase.set_raw_value
  File "jsonobject/base.pyx", line 274, in jsonobject.jsonobject.base.JsonObjectBase.__wrap
  File "jsonobject/base_properties.pyx", line 180, in jsonobject.jsonobject.base_properties.JsonContainerProperty.wrap
  File "jsonobject/containers.pyx", line 129, in jsonobject.jsonobject.containers.JsonDict.__init__
  File "jsonobject/containers.pyx", line 136, in jsonobject.jsonobject.containers.JsonDict.__wrap
  File "jsonobject/properties.pyx", line 154, in jsonobject.jsonobject.properties.ObjectProperty.wrap
  File "jsonobject/base.pyx", line 251, in jsonobject.jsonobject.base.JsonObjectBase.wrap
  File "jsonobject/base.pyx", line 204, in jsonobject.jsonobject.base.JsonObjectBase.__init__
jsonobject.exceptions.WrappingAttributeError: can't set attribute corresponding to 'foo' on a <class '__main__.A'> while wrapping {'foo': '/foo/bar'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./test2.py", line 18, in <module>
    C(c.to_json())
  File "jsonobject/base.pyx", line 204, in jsonobject.jsonobject.base.JsonObjectBase.__init__
jsonobject.exceptions.WrappingAttributeError: can't set attribute corresponding to 'components' on a <class '__main__.C'> while wrapping {'components': {'test': {'foo': '/foo/bar'}}}

Moving _allow_dynamic_properties to the subclass makes it work, but it would be really nice if this attribute didn't have to be set in each "leaf" class.

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