-
Notifications
You must be signed in to change notification settings - Fork 65
fix: skip upserting edges when nodes don't exist #158
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -156,6 +156,14 @@ def update_node(self, node_id: str, node_data: dict[str, any]): | |||||||||||||||||
| def upsert_edge( | ||||||||||||||||||
| self, source_node_id: str, target_node_id: str, edge_data: dict[str, any] | ||||||||||||||||||
| ): | ||||||||||||||||||
| # Ensure both nodes exist before adding the edge | ||||||||||||||||||
| if not self._graph.has_node(source_node_id) or not self._graph.has_node( | ||||||||||||||||||
| target_node_id | ||||||||||||||||||
| ): | ||||||||||||||||||
| print( | ||||||||||||||||||
| f"Cannot upsert edge {source_node_id} -> {target_node_id} because one or both nodes do not exist." | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
+163
to
+165
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the other storage implementation, using I suggest using Note: You will need to add
Suggested change
|
||||||||||||||||||
| return | ||||||||||||||||||
| self._graph.add_edge(source_node_id, target_node_id, **edge_data) | ||||||||||||||||||
|
|
||||||||||||||||||
| def update_edge( | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
print()for logging is generally discouraged in library code because it's not configurable by the application using the library. It's better to use theloggingmodule. This allows consumers to control log levels, format, and output destinations.I suggest using
logging.warninghere. This also uses the recommended practice of passing arguments to logging methods to defer string formatting.Note: You will need to add
import loggingat the top of the file.