[BUG]: After building the listener through graph, an error occurs when executing db.add.
Closed this issue · 0 comments
jieguangzhou commented
Contact Details [Optional]
No response
System Information
main branch
What happened?
If Variable is a key, setting is skipped
Steps to reproduce
from superduperdb import superduper
from superduperdb.backends.mongodb import Collection
db = superduper('mongomock://temp')
select = Collection("data").find()
from superduperdb import ObjectModel
model1 = ObjectModel(identifier="model1", object=lambda x: "model1_" + str(x))
model2 = ObjectModel(identifier="model2", object=lambda x1, x2: {"x1": x1, "x2":x2})
from superduperdb.components.graph import Graph, document_node, input_node
in_ = document_node('x')
output1 = model1(x=in_['x'], outputs="l1")
output2 = model2(x1=output1, x2=in_["x"], outputs="l2")
listener_stack = output2.to_listeners(select=select, identifier="listener")
db.add(listener_stack)
Relevant log output
File ~/workspace/SuperDuperDB/superduperdb/superduperdb/base/datalayer.py:484, in Datalayer.add(self, object, dependencies)
476 return type(object)(
477 self._add(
478 object=component,
(...)
481 for component in object
482 )
483 elif isinstance(object, Component):
--> 484 return self._add(object=object, dependencies=dependencies), object
485 else:
486 return self._add(superduper(object)), object
File ~/workspace/SuperDuperDB/superduperdb/superduperdb/base/datalayer.py:852, in Datalayer._add(self, object, dependencies, parent)
850 artifacts = [leaf for leaf in leaves if isinstance(leaf, _BaseEncodable)]
851 children = [leaf for leaf in leaves if isinstance(leaf, Component)]
--> 852 jobs.extend(self._add_child_components(children, parent=object))
854 # need to do this again to get the versions of the children
855 object.set_variables(self)
File ~/workspace/SuperDuperDB/superduperdb/superduperdb/base/datalayer.py:812, in Datalayer._add_child_components(self, components, parent)
808 component = lookup[n]
809 dependencies = sum(
810 [jobs.get(d[:2], []) for d in component.dependencies], []
811 )
--> 812 tmp = self._add(
813 component, parent=parent.unique_id, dependencies=dependencies
814 )
815 jobs[n] = tmp
817 return sum(list(jobs.values()), [])
File ~/workspace/SuperDuperDB/superduperdb/superduperdb/base/datalayer.py:861, in Datalayer._add(self, object, dependencies, parent)
858 if artifacts:
859 self.artifact_store.save(serialized)
--> 861 self.metadata.create_component(serialized)
863 if parent is not None:
864 self.metadata.create_parent_child(parent, object.unique_id)
File ~/workspace/SuperDuperDB/superduperdb/superduperdb/backends/mongodb/metadata.py:63, in MongoMetaDataStore.create_component(self, info)
61 if 'hidden' not in info:
62 info['hidden'] = False
---> 63 return self.component_collection.insert_one(info)
File ~/workspace/SuperDuperDB/superduperdb/env/lib/python3.10/site-packages/mongomock/collection.py:454, in Collection.insert_one(self, document, bypass_document_validation, session)
452 if not bypass_document_validation:
453 validate_is_mutable_mapping('document', document)
--> 454 return InsertOneResult(self._insert(document, session), acknowledged=True)
File ~/workspace/SuperDuperDB/superduperdb/env/lib/python3.10/site-packages/mongomock/collection.py:505, in Collection._insert(self, data, session, ordered)
501 raise ValueError('Document keys must be strings')
503 if BSON:
504 # bson validation
--> 505 BSON.encode(data, check_keys=True)
507 # Like pymongo, we should fill the _id in the inserted dict (odd behavior,
508 # but we need to stick to it), so we must patch in-place the data dict
509 if '_id' not in data:
File ~/workspace/SuperDuperDB/superduperdb/env/lib/python3.10/site-packages/bson/__init__.py:1428, in BSON.encode(cls, document, check_keys, codec_options)
1401 @classmethod
1402 def encode(
1403 cls: Type[BSON],
(...)
1406 codec_options: CodecOptions[Any] = DEFAULT_CODEC_OPTIONS,
1407 ) -> BSON:
1408 """Encode a document to a new :class:`BSON` instance.
1409
1410 A document can be any mapping type (like :class:`dict`).
(...)
1426 Replaced `uuid_subtype` option with `codec_options`.
1427 """
-> 1428 return cls(encode(document, check_keys, codec_options))
File ~/workspace/SuperDuperDB/superduperdb/env/lib/python3.10/site-packages/bson/__init__.py:1042, in encode(document, check_keys, codec_options)
1039 if not isinstance(codec_options, CodecOptions):
1040 raise _CODEC_OPTIONS_TYPE_ERROR
-> 1042 return _dict_to_bson(document, check_keys, codec_options)
InvalidDocument: documents must have only string keys, key was $_outputs.l1::{version}