fix(inference): respect table_name config in InferenceStore (backport #4371) (#4372)

# What does this PR do?

The InferenceStore class was ignoring the table_name field from
InferenceStoreReference and always using the hardcoded value
"chat_completions". This meant that any custom table_name configured in
the run config (e.g., "inference_store" in run-with-postgres-store.yaml)
was silently ignored.

This change updates all SQL operations in InferenceStore to use
self.reference.table_name instead of the hardcoded string, ensuring the
configured table name is properly respected.

A new test has been added to verify that custom table names work
correctly for storing, retrieving, and listing chat completions.




## Test Plan

CI

<hr>This is an automatic backport of pull request #4371 done by
[Mergify](https://mergify.com).

Signed-off-by: Sébastien Han <seb@redhat.com>
Co-authored-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
mergify[bot] 2025-12-11 15:07:35 +01:00 committed by GitHub
parent 254adf2e10
commit a6a600f845
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 5 deletions

View file

@ -56,7 +56,7 @@ class InferenceStore:
logger.debug("Write queue disabled for SQLite (WAL mode handles concurrency)")
await self.sql_store.create_table(
"chat_completions",
self.reference.table_name,
{
"id": ColumnDefinition(type=ColumnType.STRING, primary_key=True),
"created": ColumnType.INTEGER,
@ -161,7 +161,7 @@ class InferenceStore:
try:
await self.sql_store.insert(
table="chat_completions",
table=self.reference.table_name,
data=record_data,
)
except IntegrityError as e:
@ -173,7 +173,7 @@ class InferenceStore:
error_message = str(e.orig) if e.orig else str(e)
if self._is_unique_constraint_error(error_message):
# Update the existing record instead
await self.sql_store.update(table="chat_completions", data=record_data, where={"id": data["id"]})
await self.sql_store.update(table=self.reference.table_name, data=record_data, where={"id": data["id"]})
else:
# Re-raise if it's not a unique constraint error
raise
@ -217,7 +217,7 @@ class InferenceStore:
where_conditions["model"] = model
paginated_result = await self.sql_store.fetch_all(
table="chat_completions",
table=self.reference.table_name,
where=where_conditions if where_conditions else None,
order_by=[("created", order.value)],
cursor=("id", after) if after else None,
@ -246,7 +246,7 @@ class InferenceStore:
raise ValueError("Inference store is not initialized")
row = await self.sql_store.fetch_one(
table="chat_completions",
table=self.reference.table_name,
where={"id": completion_id},
)