Box icon indicating copy to clipboard operation
Box copied to clipboard

Segfault (infinite recursion?) when loading YAML schema into Box with `box_dots=True`

Open brynpickering opened this issue 1 year ago • 5 comments
trafficstars

I have a YAML schema (see here) which I want to be able to get the flattened dict keys for - something that Box is well placed to provide with its dot notation.

However, I get a segfault when loading the YAML file with:

from box import Box
schema = Box.from_yaml("path/to/schema.yaml", default_box=True, box_dots=True)

It loads successfully with:

from box import Box
schema = Box.from_yaml("path/to/schema.yaml")

But then I lose the ability to inspect the flattened keys (schema.keys(dotted=True)).

brynpickering avatar Jan 25 '24 12:01 brynpickering

Confirmed with that file the behavior, with both ruamel.yaml and pyyaml as backends, so is from something in my code side looping. Thanks for raising the issue will look into!

cdgriffith avatar Jan 25 '24 19:01 cdgriffith

Anything new on this one? I have a similar problem but with some JSON:

Box.from_yaml(resp.text, box_dots=True)
Traceback (most recent call last):
  File ".../pydevd_asyncio_utils.py", line 117, in _exec_async_code
    result = func()
  File "<input>", line 1, in <module>
  File "box/box.py", line 1050, in box.box.Box.from_yaml
  File "box/box.py", line 291, in box.box.Box.__init__
  File "box/box.py", line 671, in box.box.Box.__setitem__
  File "box/box.py", line 574, in box.box.Box.__convert_and_store
  File "box/box.py", line 291, in box.box.Box.__init__
  File "box/box.py", line 671, in box.box.Box.__setitem__
  File "box/box.py", line 583, in box.box.Box.__convert_and_store
  File "box/box_list.py", line 52, in box.box_list.BoxList.__init__
  File "box/box_list.py", line 110, in box.box_list.BoxList.append
  File "box/box_list.py", line 100, in box.box_list.BoxList._convert
  File "box/box.py", line 291, in box.box.Box.__init__
  File "box/box.py", line 671, in box.box.Box.__setitem__
  File "box/box.py", line 574, in box.box.Box.__convert_and_store
  File "box/box.py", line 291, in box.box.Box.__init__
  File "box/box.py", line 671, in box.box.Box.__setitem__
  File "box/box.py", line 574, in box.box.Box.__convert_and_store
  File "box/box.py", line 291, in box.box.Box.__init__
  File "box/box.py", line 664, in box.box.Box.__setitem__
box.exceptions.BoxKeyError: "'<class 'box.box.Box'>' object has no attribute tenant"

paulschroeder-tomtom avatar Apr 19 '24 12:04 paulschroeder-tomtom

I am pretty sure Box chokes on / or . in the... keys maybe?

...
metadata:
  labels:
    kubed.appscode.com/origin.cluster: unicorn
...
Traceback (most recent call last):
  File "/home/schroederp/.local/share/JetBrains/IntelliJIdea2024.1/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "box/box.py", line 303, in box.box.Box.__init__
  File "box/box.py", line 671, in box.box.Box.__setitem__
  File "box/box.py", line 574, in box.box.Box.__convert_and_store
  File "box/box.py", line 291, in box.box.Box.__init__
  File "box/box.py", line 671, in box.box.Box.__setitem__
  File "box/box.py", line 574, in box.box.Box.__convert_and_store
  File "box/box.py", line 291, in box.box.Box.__init__
  File "box/box.py", line 664, in box.box.Box.__setitem__
box.exceptions.BoxKeyError: "'<class 'box.box.Box'>' object has no attribute kubed"

paulschroeder-tomtom avatar May 03 '24 13:05 paulschroeder-tomtom

@paulschroeder-tomtom good find, yes.

If there are keys with . or [] in them, box dots will treat them as if they should break them apart.

For example in @brynpickering YAML has keys like '^[^_^\d][\w]*$': {} that it will fail on.

I don't see any what Box could really support those cases, but should at least have a check on box creation if something is going to break it like that and give a clear error.

cdgriffith avatar Jun 12 '24 15:06 cdgriffith

Ok, I sad but then it is like that. WIll you create an improve on the error message?

paulschroeder-tomtom avatar Jun 21 '24 09:06 paulschroeder-tomtom