Skip to content

Conversation

@sivukhin
Copy link
Contributor

@sivukhin sivukhin commented Dec 16, 2025

Sync feature for tursodb uses CDC which will affect lastInsertRowid as internally every insert will also insert data to the CDC table.

In order to properly work in sync context - we need to explicitly return inserted rowid from the query with RETURNING clause

sivukhin and others added 7 commits December 16, 2025 15:40
- lastInsertRowid will work incorrectly with sync as it enabled CDC and in this case lastInsertRowid will hold rowid of CDC entry
This change updates the Python SDK to match the TypeScript SDK's approach
of using SQL RETURNING clauses instead of relying on lastInsertRowid for
INSERT operations. This is based on commit fa77931.

Key changes:
- filesystem.py: Updated _create_inode() to use RETURNING ino
- toolcalls.py: Updated start() and record() to use RETURNING id

Technical implementation notes:
- When using RETURNING with turso.aio, we must explicitly create and close
  cursors to avoid busy/lock errors when CDC is enabled
- The cursor must be closed before committing the transaction
- Pattern: create cursor → execute with RETURNING → fetch result →
  close cursor → commit → return result

This ensures the SDK works correctly with TursoDB connections that have
CDC (Change Data Capture) enabled via the PRAGMA
unstable_capture_data_changes_conn('full') setting.

All 95 tests pass successfully after this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
This change updates the Python SDK tests to enable Change Data Capture (CDC)
by default, matching the TypeScript SDK implementation from commit 9c49f31.

## Motivation

The TypeScript SDK recently enabled CDC in all tests to ensure that AgentFS
components work properly when CDC is enabled - which is critical for sync
functionality. The Python SDK needs the same testing coverage to maintain
parity and ensure reliability.

## Changes

Added CDC enablement pragma after every database connection in test files:
- test_filesystem.py: 40 test methods updated
- test_toolcalls.py: 22 test methods updated
- test_kvstore.py: 19 test methods updated
- Total: 81 CDC pragma additions

Pattern applied:
```python
db = await connect(db_path)
await db.execute("PRAGMA unstable_capture_data_changes_conn('full')")
```

This matches the TypeScript pattern:
```typescript
await db.exec("PRAGMA unstable_capture_data_changes_conn('full')");
```

Note: The Python turso.aio API uses execute() instead of exec().

## Testing

All 95 tests pass successfully, confirming:
- CDC pragma is correctly positioned (after connection, before operations)
- Syntax is correct for Python turso.aio library
- No functionality breaks with CDC enabled
- Python SDK now properly tests CDC compatibility like TypeScript SDK

## Related commits

- 9c49f31: Enable CDC in tests by default for TS sdk
- 8d35138: Use RETURNING clause instead of lastInsertRowid in Python SDK
- b2b5647: Use RETURNING clause instead of lastInsertRowid (TS SDK)

The RETURNING clause changes (8d35138) were specifically designed to work
with CDC-enabled connections, and these test updates validate that design.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@penberg penberg merged commit 5cdc362 into tursodatabase:main Dec 16, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants