Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions graphgen/models/storage/graph/kuzu_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ def upsert_edge(
Note: We explicitly ensure nodes exist before merging the edge to avoid errors,
although GraphGen generally creates nodes before edges.
"""
# Ensure source node exists
if not self.has_node(source_node_id):
self.upsert_node(source_node_id, {})
# Ensure target node exists
if not self.has_node(target_node_id):
self.upsert_node(target_node_id, {})
# Ensure source node exists and target node exists
if not self.has_node(source_node_id) or not self.has_node(target_node_id):
print(
f"Cannot upsert edge {source_node_id}->{target_node_id} as one or both nodes do not exist."
)
Comment on lines +348 to +350
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 the logging module. This allows consumers to control log levels, format, and output destinations.

I suggest using logging.warning here. This also uses the recommended practice of passing arguments to logging methods to defer string formatting.

Note: You will need to add import logging at the top of the file.

Suggested change
print(
f"Cannot upsert edge {source_node_id}->{target_node_id} as one or both nodes do not exist."
)
logging.warning(
"Cannot upsert edge %s->%s as one or both nodes do not exist.",
source_node_id,
target_node_id,
)

return

try:
json_data = json.dumps(edge_data, ensure_ascii=False)
Expand Down
8 changes: 8 additions & 0 deletions graphgen/models/storage/graph/networkx_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As with the other storage implementation, using print() for logging is not ideal. Using the logging module provides better control for consumers of this library.

I suggest using logging.warning here. This also uses the recommended practice of passing arguments to logging methods to defer string formatting.

Note: You will need to add import logging at the top of the file.

Suggested change
print(
f"Cannot upsert edge {source_node_id} -> {target_node_id} because one or both nodes do not exist."
)
logging.warning(
"Cannot upsert edge %s -> %s because one or both nodes do not exist.",
source_node_id,
target_node_id,
)

return
self._graph.add_edge(source_node_id, target_node_id, **edge_data)

def update_edge(
Expand Down
Loading