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

Dumping boxes doesn't work well #78

Closed
loganasherjones opened this issue Jun 12, 2018 · 1 comment
Closed

Dumping boxes doesn't work well #78

loganasherjones opened this issue Jun 12, 2018 · 1 comment

Comments

@loganasherjones
Copy link
Owner

There are lots of hidden objects on a Box when yaml attempts to dump them. This is very annoying since our configs are often times Box objects. By default, I should check to make sure that when we are dumping data, if it is a Box to call to_dict on it.

@loganasherjones
Copy link
Owner Author

As an example, for the simple ascii_data:

from box import Box

data = {
    'foo': 'bar',
    'db': {'name': 'db_name', 'port': 123},
    'items': [1, 2, 3]
}

When using yapconf to dump, we would get:

>> yapconf.dump_data(Box(data), file_type='yaml')
&id001 !!python/object/new:box.Box
dictitems:
  db: !!python/object/new:box.Box
    dictitems:
      name: db_name
      port: 123
    state:
      _box_config:
        __box_heritage: !!python/tuple
        - *id001
        - db
        __converted: !!set
          name: null
          port: null
        __created: true
        __hash: null
        box_duplicates: ignore
        box_safe_prefix: x
        camel_killer_box: false
        conversion_box: true
        default_box: false
        default_box_attr: &id002 !!python/name:box.Box ''
        frozen_box: false
        modify_tuples_box: false
        ordered_box: false
  foo: bar
  items: !!python/object/new:box.BoxList
    listitems:
    - 1
    - 2
    - 3
    state:
      box_class: *id002
      box_options:
        __box_heritage: !!python/tuple
        - *id001
        - items
        box_duplicates: ignore
        box_safe_prefix: x
        camel_killer_box: false
        conversion_box: true
        default_box: false
        default_box_attr: *id002
        frozen_box: false
        modify_tuples_box: false
        ordered_box: false
      box_org_ref: 140087657129096
state:
  _box_config:
    __box_heritage: null
    __converted: !!set
      db: null
      foo: null
      items: null
    __created: true
    __hash: null
    box_duplicates: ignore
    box_safe_prefix: x
    camel_killer_box: false
    conversion_box: true
    default_box: false
    default_box_attr: *id002
    frozen_box: false
    modify_tuples_box: false
    ordered_box: false

We should expect to get:

db:
  name: db_name
  port: 123
foo: bar
items:
- 1
- 2
- 3

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

1 participant