# Buggy code
def to_dict(self):
    """Convert metadata to a dict

    Returns:
        dict: metadata as a dict
    """
    return self.copy()


# Traceback (RepresenterError)
In [28]: package.to_yaml('test.yml')
---------------------------------------------------------------------------
RepresenterError                          Traceback (most recent call last)
~/.local/lib/python3.8/site-packages/frictionless/metadata.py in to_yaml(self, target)
137             with tempfile.NamedTemporaryFile("wt", delete=False) as file:
--> 138                 yaml.dump(self.to_dict(), file, Dumper=IndentDumper)
139             helpers.move_file(file.name, target)

/usr/lib/python3.8/site-packages/yaml/__init__.py in dump(data, stream, Dumper, **kwds)
289     """
--> 290     return dump_all([data], stream, Dumper=Dumper, **kwds)
291

/usr/lib/python3.8/site-packages/yaml/__init__.py in dump_all(documents, stream, Dumper, default_style, default_flow_style, canonical, indent, width, allow_unicode, line_break, encoding, explicit_start, explicit_end, version, tags, sort_keys)
277         for data in documents:
--> 278             dumper.represent(data)
279         dumper.close()

/usr/lib/python3.8/site-packages/yaml/representer.py in represent(self, data)
26     def represent(self, data):
---> 27         node = self.represent_data(data)
28         self.serialize(node)

/usr/lib/python3.8/site-packages/yaml/representer.py in represent_data(self, data)
47         if data_types[0] in self.yaml_representers:
---> 48             node = self.yaml_representers[data_types[0]](self, data)
49         else:

/usr/lib/python3.8/site-packages/yaml/representer.py in represent_dict(self, data)
206     def represent_dict(self, data):
--> 207         return self.represent_mapping('tag:yaml.org,2002:map', data)
208

/usr/lib/python3.8/site-packages/yaml/representer.py in represent_mapping(self, tag, mapping, flow_style)
117             node_key = self.represent_data(item_key)
--> 118             node_value = self.represent_data(item_value)
119             if not (isinstance(node_key, ScalarNode) and not node_key.style):

/usr/lib/python3.8/site-packages/yaml/representer.py in represent_data(self, data)
57                 elif None in self.yaml_representers:
---> 58                     node = self.yaml_representers[None](self, data)
59                 else:

/usr/lib/python3.8/site-packages/yaml/representer.py in represent_undefined(self, data)
230     def represent_undefined(self, data):
--> 231         raise RepresenterError("cannot represent an object", data)
232

RepresenterError: ('cannot represent an object', [{'path': 'test/data/data.csv', 'control': {'newline': ''}, 'schema': {'fields': [{'name': 'atomic number', 'type': 'integer'}, {'name': 'symbol', 'type': 'string'}, {'name': 'name', 'type': 'string'}, {'name': 'atomic mass', 'type': 'number'}, {'name': 'metal or nonmetal?', 'type': 'string'}]}, 'profile': 'tabular-data-resource', 'name': 'data', 'scheme': 'file', 'format': 'csv', 'hashing': 'md5', 'encoding': 'utf-8', 'compression': 'no', 'compressionPath': '', 'dialect': {}, 'query': {}, 'stats': {'hash': 'ec86e3663d1e497ff100dc66002cb88b', 'bytes': 4252, 'fields': 5, 'rows': 118}}])

# Fixed code
def to_dict(self):
    """Convert metadata to a dict

    Returns:
        dict: metadata as a dict
    """
    return helpers.deepnative(self)