Skip to content

feature: Be able to update different attributes and relationships of a node with a dict #272

Description

@BeArchiTek

Component

Python SDK

Describe the Feature Request

Right now, we can provide a dict when we create a new node, as a user I would like to have a similar function to be able to update an existing node.

Describe the Use Case

It will allow to update node in a cleaner manner in integrations

Additional Information

I currently have something like this to do it :

            for attr_name in data:
                if attr_name in tmp_obj._schema.attribute_names:
                    attr_schema = next(attr for attr in tmp_obj._schema.attributes if attr.name == attr_name)
                    attr_data = data.get(attr_name)
                    new_attr = Attribute(name=attr_name, schema=attr_schema, data=attr_data)
                    setattr(tmp_obj, attr_name, new_attr)
                elif attr_name in tmp_obj._schema.relationship_names:
                    rel_schema = next(rel for rel in self._schema.relationships if rel.name == attr_name)
                    rel_data = data.get(attr_name)
                    if rel_schema.cardinality == RelationshipCardinality.ONE:
                        setattr(tmp_obj, f"_{attr_name}", None)
                        setattr(
                            tmp_obj,
                            attr_name,
                            generate_relationship_property(name=attr_name, node=tmp_obj),
                        )
                    elif rel_schema.cardinality == RelationshipCardinality.MANY:
                        setattr(
                            tmp_obj,
                            attr_name,
                            RelationshipManagerSync(
                                name=attr_name,
                                client=tmp_obj._client,
                                node=tmp_obj,
                                branch=tmp_obj._branch,
                                schema=rel_schema,
                                data=rel_data,
                            ),
                        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions