In Customer Support Bot tutorial, the backup db file is created too early so dates aren't current. #203

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

Originally created by @florentremis on GitHub (Aug 23, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph/LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph/LangChain rather than my code.
  • I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code

### Database file initialization

import os
import shutil
import sqlite3

import pandas as pd
import requests

db_url = "https://storage.googleapis.com/benchmarks-artifacts/travel-db/travel2.sqlite"
local_file = "travel2.sqlite"
# The backup lets us restart for each tutorial section
backup_file = "travel2.backup.sqlite"
overwrite = False
if overwrite or not os.path.exists(local_file):
    response = requests.get(db_url)
    response.raise_for_status()  # Ensure the request was successful
    with open(local_file, "wb") as f:
        f.write(response.content)
    # Backup - we will use this to "reset" our DB in each section
    shutil.copy(local_file, backup_file)
# Convert the flights to present time for our tutorial
conn = sqlite3.connect(local_file)
cursor = conn.cursor()

tables = pd.read_sql(
    "SELECT name FROM sqlite_master WHERE type='table';", conn
).name.tolist()
tdf = {}
for t in tables:
    tdf[t] = pd.read_sql(f"SELECT * from {t}", conn)

example_time = pd.to_datetime(
    tdf["flights"]["actual_departure"].replace("\\N", pd.NaT)
).max()
current_time = pd.to_datetime("now").tz_localize(example_time.tz)
time_diff = current_time - example_time

tdf["bookings"]["book_date"] = (
    pd.to_datetime(tdf["bookings"]["book_date"].replace("\\N", pd.NaT), utc=True)
    + time_diff
)

datetime_columns = [
    "scheduled_departure",
    "scheduled_arrival",
    "actual_departure",
    "actual_arrival",
]
for column in datetime_columns:
    tdf["flights"][column] = (
        pd.to_datetime(tdf["flights"][column].replace("\\N", pd.NaT)) + time_diff
    )

for table_name, df in tdf.items():
    df.to_sql(table_name, conn, if_exists="replace", index=False)
del df
del tdf
conn.commit()
conn.close()

db = local_file  # We'll be using this local file as our DB in this tutorial

### End of initialization

### And here's what's before every test of the bot ###
# Update with the backup file so we can restart from the original place in each section
shutil.copy(backup_file, db)

Error Message and Stack Trace (if applicable)

No response

Description

In the Customer Support Bot tutorial, when initializing the DB, the backup file is created before the dates in the DB are updated to be current.

Unfortunately before every execution of the graph, the backup file is reloaded and the dates aren't re-updated, so the dates are back to being old and since the bot uses the current date as a reference to book a new flight, it can't find relevant entries in the DB.

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64
Python Version: 3.12.3 (v3.12.3:f6650f9ad7, Apr 9 2024, 08:18:48) [Clang 13.0.0 (clang-1300.0.29.30)]

Package Information

langchain_core: 0.2.28
langchain: 0.2.12
langchain_community: 0.2.11
langsmith: 0.1.96
langchain_chroma: 0.1.2
langchain_google_vertexai: 1.0.8
langchain_text_splitters: 0.2.2
langchainhub: 0.1.21
langgraph: 0.2.0
langserve: 0.2.2

Originally created by @florentremis on GitHub (Aug 23, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the [LangGraph](https://langchain-ai.github.io/langgraph/)/LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangGraph/LangChain rather than my code. - [X] I am sure this is better as an issue [rather than a GitHub discussion](https://github.com/langchain-ai/langgraph/discussions/new/choose), since this is a LangGraph bug and not a design question. ### Example Code ```python ### Database file initialization import os import shutil import sqlite3 import pandas as pd import requests db_url = "https://storage.googleapis.com/benchmarks-artifacts/travel-db/travel2.sqlite" local_file = "travel2.sqlite" # The backup lets us restart for each tutorial section backup_file = "travel2.backup.sqlite" overwrite = False if overwrite or not os.path.exists(local_file): response = requests.get(db_url) response.raise_for_status() # Ensure the request was successful with open(local_file, "wb") as f: f.write(response.content) # Backup - we will use this to "reset" our DB in each section shutil.copy(local_file, backup_file) # Convert the flights to present time for our tutorial conn = sqlite3.connect(local_file) cursor = conn.cursor() tables = pd.read_sql( "SELECT name FROM sqlite_master WHERE type='table';", conn ).name.tolist() tdf = {} for t in tables: tdf[t] = pd.read_sql(f"SELECT * from {t}", conn) example_time = pd.to_datetime( tdf["flights"]["actual_departure"].replace("\\N", pd.NaT) ).max() current_time = pd.to_datetime("now").tz_localize(example_time.tz) time_diff = current_time - example_time tdf["bookings"]["book_date"] = ( pd.to_datetime(tdf["bookings"]["book_date"].replace("\\N", pd.NaT), utc=True) + time_diff ) datetime_columns = [ "scheduled_departure", "scheduled_arrival", "actual_departure", "actual_arrival", ] for column in datetime_columns: tdf["flights"][column] = ( pd.to_datetime(tdf["flights"][column].replace("\\N", pd.NaT)) + time_diff ) for table_name, df in tdf.items(): df.to_sql(table_name, conn, if_exists="replace", index=False) del df del tdf conn.commit() conn.close() db = local_file # We'll be using this local file as our DB in this tutorial ### End of initialization ### And here's what's before every test of the bot ### # Update with the backup file so we can restart from the original place in each section shutil.copy(backup_file, db) ``` ### Error Message and Stack Trace (if applicable) _No response_ ### Description In the [Customer Support Bot tutorial](https://langchain-ai.github.io/langgraph/tutorials/customer-support/customer-support/#populate-the-database), when initializing the DB, the backup file is created before the dates in the DB are updated to be current. Unfortunately before every execution of the graph, the backup file is reloaded and the dates aren't re-updated, so the dates are back to being old and since the bot uses the current date as a reference to book a new flight, it can't find relevant entries in the DB. ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64 > Python Version: 3.12.3 (v3.12.3:f6650f9ad7, Apr 9 2024, 08:18:48) [Clang 13.0.0 (clang-1300.0.29.30)] Package Information ------------------- > langchain_core: 0.2.28 > langchain: 0.2.12 > langchain_community: 0.2.11 > langsmith: 0.1.96 > langchain_chroma: 0.1.2 > langchain_google_vertexai: 1.0.8 > langchain_text_splitters: 0.2.2 > langchainhub: 0.1.21 > langgraph: 0.2.0 > langserve: 0.2.2
yindo closed this issue 2026-02-20 17:31:31 -05:00
Author
Owner

@isahers1 commented on GitHub (Aug 26, 2024):

should be fixed here: https://github.com/langchain-ai/langgraph/pull/1487

@isahers1 commented on GitHub (Aug 26, 2024): should be fixed here: https://github.com/langchain-ai/langgraph/pull/1487
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#203