beetbox / beetbox/confuse

Problems with Sequence template

Open
#137 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
424
Forks
57
PR merge metrics
No merged PRs in 30d

Description

I am trying to use confuse examples to dynamically update a Sequence, but `dump` function is not working after dynamic update:

`servers_example.yaml`:
```
servers:
- host: one.example.com
- host: two.example.com
port: 8000
- host: three.example.com
port: 8080
```

`test.py`:
```
import confuse
import pprint
source = confuse.YamlSource('servers_example.yaml')
config = confuse.Configuration(__file__)
config.add(source)
template = {
'servers': confuse.Sequence({
'host': str,
'port': 80,
}),
}
valid_config = config.get(template)
pprint.pprint(valid_config)

config.set({
'servers': valid_config['servers'] + [
{'host': 'four.example.org'},
{'host': 'five.example.org', 'port': 9000},
],
})
updated_config = config.get(template)
pprint.pprint(updated_config)

print(config.dump(full=False).strip())

```

`config.dump` produces:

```
Traceback (most recent call last):
File "test.py", line 26, in
print(config.dump(full=False).strip())
File "/usr/local/lib/python3.8/dist-packages/confuse/core.py", line 717, in dump
yaml_out = yaml.dump(out_dict, Dumper=yaml_util.Dumper,
File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 290, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 278, in dump_all
dumper.represent(data)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 27, in represent
node = self.represent_data(data)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 207, in represent_dict
return self.represent_mapping('tag:yaml.org,2002:map', data)
File "/usr/local/lib/python3.8/dist-packages/confuse/yaml_util.py", line 108, in represent_mapping
node_value = self.represent_data(item_value)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "/usr/local/lib/python3.8/dist-packages/confuse/yaml_util.py", line 127, in represent_list
node = super(Dumper, self).represent_list(data)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 199, in represent_list
return self.represent_sequence('tag:yaml.org,2002:seq', data)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 92, in represent_sequence
node_item = self.represent_data(item)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 58, in represent_data
node = self.yaml_representers[None](self, data)
File "/usr/lib/python3/dist-packages/yaml/representer.py", line 231, in represent_undefined
raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', {'host': 'one.example.com', 'port': 80})

```

Any idea what am I doing wrong? or is it a bug?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.