Fix created_at field type in Variable and ApiKey models (#1792)

* Fix created_at field type in Variable model

* Fix created_at field type in ApiKey model

* Fix error handling in add_row_to_table function

#1790

* Apply type hinting to nest_asyncio import in load.py
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-04-29 11:26:45 -03:00 committed by GitHub
commit 3f07a39f5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 4 deletions

View file

@ -104,7 +104,7 @@ def run_flow_from_json(
"""
# Set all streaming to false
try:
import nest_asyncio
import nest_asyncio # type: ignore
nest_asyncio.apply()
except Exception as e:

View file

@ -22,7 +22,7 @@ class ApiKeyBase(SQLModel):
class ApiKey(ApiKeyBase, table=True):
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
created_at: datetime = Field(
created_at: Optional[datetime] = Field(
default=None, sa_column=Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
)
api_key: str = Field(index=True, unique=True)

View file

@ -25,7 +25,7 @@ class Variable(VariableBase, table=True):
description="Unique ID for the variable",
)
# name is unique per user
created_at: datetime = Field(
created_at: Optional[datetime] = Field(
default=None,
sa_column=Column(DateTime(timezone=True), server_default=func.now(), nullable=True),
description="Creation time of the variable",

View file

@ -101,10 +101,16 @@ def add_row_to_table(
conn.execute(insert_sql, values)
except Exception as e:
# Log values types
column_error_message = ""
for key, value in validated_dict.items():
logger.error(f"{key}: {type(value)}")
if value in str(e):
column_error_message = f"Column: {key} Value: {value} Error: {e}"
logger.error(f"Error adding row to table: {e}")
if column_error_message:
logger.error(f"Error adding row to {table_name}: {column_error_message}")
else:
logger.error(f"Error adding row to {table_name}: {e}")
async def log_message(