Skip to content

v4.5.1

Choose a tag to compare

@nhumrich nhumrich released this 22 Oct 04:49
· 38 commits to main since this release

Bug Fixes

Fix datetime serialization (#tsql-30)

Previously, datetime, date, time, and timedelta objects were being serialized to strings via format_field() before being passed to database drivers. This caused drivers like asyncpg to reject parameters with DataError: expected a datetime.date or datetime.datetime instance, got 'str'.

Fixed: These types are now preserved as native Python objects when no format spec is provided, allowing database drivers to handle them correctly.

# Now works correctly with asyncpg
cutoff = datetime.datetime.now() - datetime.timedelta(minutes=15)
query = t"SELECT * FROM users WHERE created_at > {cutoff}"

Fix Template objects in INSERT/UPDATE (#tsql-31)

Using t"" syntax for SQL expressions in INSERT/UPDATE statements (e.g., activated_ts=t"NOW()") was incorrectly treating the Template object as a parameter value instead of inline SQL. This caused asyncpg to throw DataError: expected a datetime.date or datetime.datetime instance, got 'Template'.

Fixed: Template, TSQL, and QueryBuilder objects are now properly recognized and inlined as SQL in INSERT/UPDATE operations.

# Now works correctly - NOW() is inlined as SQL
query = Users.update(updated_ts=t"NOW()").where(Users.id == 123)
# Produces: UPDATE users SET updated_ts = NOW() WHERE users.id = ?

# Also works with SQL expressions
query = Users.insert(name="Alice", created_ts=t"NOW() - INTERVAL '5 minutes'")