Bug in Item class: updated_at incorrectly initialized with created_at value #500

Closed
opened 2026-02-20 17:40:27 -05:00 by yindo · 1 comment
Owner

Originally created by @dssugar on GitHub (Mar 8, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

from langgraph.store.base import Item
from datetime import datetime, timezone

# Create an Item with string datetime values
try:
    item = Item(
        value={"key": "value"},
        key="test",
        namespace=("test",),
        created_at="2025-01-01T00:00:00+00:00",
        updated_at="2025-01-02T12:30:00+00:00"  # This should be different from created_at
    )
    
    # Print both timestamps to show they're identical
    print(f"Created at: {item.created_at}")
    print(f"Updated at: {item.updated_at}")
    
    # Show they are identical
    print(f"Are timestamps identical? {item.created_at == item.updated_at}")
    
    # Show the source of the issue by looking at the code
    import inspect
    print("\nRelevant code in Item.__init__:")
    print(inspect.getsource(Item.__init__))
    
except Exception as e:
    print(f"Error: {e}")

Error Message and Stack Trace (if applicable)


Description

I discovered a bug in the Item class initialization method in langgraph.store.base.

When an Item object is created with string datetime values (which happens during deserialization), the code incorrectly uses the created_at value to set the updated_at attribute, even when a different updated_at value is provided.

In the Item.init method, there's a line:

self.updated_at = (
    datetime.fromisoformat(cast(str, created_at))  # Bug: using created_at instead of updated_at
    if isinstance(updated_at, str)
    else updated_at
)

The condition checks if updated_at is a string, but then uses created_at for conversion. This causes both timestamps to be identical when string values are provided, which is incorrect behavior.
Expected behavior: The updated_at attribute should use the provided updated_at value, not the created_at value.
This bug could cause issues in applications that rely on the difference between creation and update timestamps, especially when deserializing data from JSON or when using persistent stores.

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-4 (2024-11-06T15:04Z)
Python Version: 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0]

Package Information

langchain_core: 0.3.43
langchain: 0.3.20
langsmith: 0.3.13
langgraph_sdk: 0.1.55

Originally created by @dssugar on GitHub (Mar 8, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python from langgraph.store.base import Item from datetime import datetime, timezone # Create an Item with string datetime values try: item = Item( value={"key": "value"}, key="test", namespace=("test",), created_at="2025-01-01T00:00:00+00:00", updated_at="2025-01-02T12:30:00+00:00" # This should be different from created_at ) # Print both timestamps to show they're identical print(f"Created at: {item.created_at}") print(f"Updated at: {item.updated_at}") # Show they are identical print(f"Are timestamps identical? {item.created_at == item.updated_at}") # Show the source of the issue by looking at the code import inspect print("\nRelevant code in Item.__init__:") print(inspect.getsource(Item.__init__)) except Exception as e: print(f"Error: {e}") ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description I discovered a bug in the Item class initialization method in langgraph.store.base. When an Item object is created with string datetime values (which happens during deserialization), the code incorrectly uses the `created_at` value to set the `updated_at` attribute, even when a different `updated_at` value is provided. In the Item.__init__ method, there's a line: ```python self.updated_at = ( datetime.fromisoformat(cast(str, created_at)) # Bug: using created_at instead of updated_at if isinstance(updated_at, str) else updated_at ) ``` The condition checks if updated_at is a string, but then uses created_at for conversion. This causes both timestamps to be identical when string values are provided, which is incorrect behavior. Expected behavior: The updated_at attribute should use the provided updated_at value, not the created_at value. This bug could cause issues in applications that rely on the difference between creation and update timestamps, especially when deserializing data from JSON or when using persistent stores. ### System Info System Information ------------------ > OS: Linux > OS Version: #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-4 (2024-11-06T15:04Z) > Python Version: 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] Package Information ------------------- > langchain_core: 0.3.43 > langchain: 0.3.20 > langsmith: 0.3.13 > langgraph_sdk: 0.1.55
yindo closed this issue 2026-02-20 17:40:27 -05:00
Author
Owner

@hinthornw commented on GitHub (Mar 10, 2025):

Thank you for flagging!

@hinthornw commented on GitHub (Mar 10, 2025): Thank you for flagging!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#500