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

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

Open
brynpickering opened this issue Jan 25, 2024 · 5 comments
Labels

Comments

@brynpickering
Copy link

brynpickering commented Jan 25, 2024

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)).

@cdgriffith cdgriffith added the bug label Jan 25, 2024
@cdgriffith
Copy link
Owner

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!

@paulschroeder-tomtom
Copy link

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
Copy link

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"

@cdgriffith
Copy link
Owner

@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.

@paulschroeder-tomtom
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants